
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
koa-response2
Advanced tools
Inspired by koa-respond. Checkout what's the difference.
$ yarn add koa-response2
import Koa, { ParameterizedContext } from 'koa'
import koaReponse from 'koa-response2'
const app = new Koa()
app.use(koaReponse())
export default function (ctx: ParameterizedContext) {
ctx.oK({ id: 123, name: 'Dat Boi' }) // HTTP Code: 200, Response: { id: 123, name: 'Dat Boi' }
ctx.notFound('Not found, boii') // HTTP Code: 404, Response: 'Not found, boii'
ctx.internalServerError('error') // HTTP Code: 500, Response: 'error'
ctx.send(200, { name: 'tom' }, 'success')
}
export interface KoaResponse {
statusMap?: Record<string, number>
format?: (status: number, payload?: any, message?: string) => any
}
Object
false
Override built-in HTTP status map, e.g.:
import Koa, { ParameterizedContext } from 'koa'
import koaReponse from 'koa-response2'
const app = new Koa()
app.use(koaReponse({
statusMap: {
whatever: 999
}
}))
ctx.whatever(data, message)
For better typing experience, you should override declaration file like this.
Function
false
Modify HTTP response globally, e.g.:
import Koa, { ParameterizedContext } from 'koa'
import koaReponse from 'koa-response2'
const app = new Koa()
// This will wrap all reponse with { code: number, data: T: message?: string } construct.
app.use(koaReponse({
format (status, payload, message = '') {
return {
code: status,
data: payload,
message
}
}
}))
koa-response2
is inspired by koa-respond, so what's the difference between the two?
koa-response2
add bulk APIs on koa.Context, you can see the whole list below.
name | code |
---|---|
oK | 200 |
created | 201 |
accepted | 202 |
nonAuthoritativeInformation | 203 |
partialContent | 206 |
multipleChoices | 300 |
badRequest | 400 |
unauthorized | 401 |
paymentRequired | 402 |
forbidden | 403 |
notFound | 404 |
methodNotAllowed | 405 |
notAcceptable | 406 |
requestTimeout | 408 |
conflict | 409 |
gone | 410 |
lengthRequired | 411 |
preconditionFailed | 412 |
payloadTooLarge | 413 |
requestURITooLong | 414 |
unsupportedMediaType | 415 |
requestedRangeNotSatisfiable | 416 |
expectationFailed | 417 |
imATeapot | 418 |
misdirectedRequest | 421 |
unprocessableEntity | 422 |
locked | 423 |
failedDependency | 424 |
upgradeRequired | 426 |
preconditionRequired | 428 |
tooManyRequests | 429 |
requestHeaderFieldsTooLarge | 431 |
unavailableForLegalReasons | 451 |
internalServerError | 500 |
notImplemented | 501 |
badGateway | 502 |
serviceUnavailable | 503 |
gatewayTimeout | 504 |
hTTPVersionNotSupported | 505 |
variantAlsoNegotiates | 506 |
insufficientStorage | 507 |
loopDetected | 508 |
notExtended | 510 |
networkAuthenticationRequired | 511 |
networkConnectTimeoutError | 599 |
Copyright (c) 2019-present, Army-U
FAQs
Unknown package
The npm package koa-response2 receives a total of 101 weekly downloads. As such, koa-response2 popularity was classified as not popular.
We found that koa-response2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.