Current collected state Current
Observed since 20 Oct, 22:12 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
@0layimika/api-response-kit
A typed toolkit for consistent API success and error responses
A small, TypeScript-first toolkit for consistent API success and error responses.
Most APIs suffer from the same problems:
throw new Error, random JSON)res.status().json() everywhereapi-response-kit fixes this by enforcing a predictable response contract for both success and error responses while keeping your code clean and framework-agnostic.
Instead of:
res.status(200).json(user)
res.status(400).json({ error: "Invalid input" })
You write:
return Ok(user)
return BadRequest("Invalid input")
type ApiSuccess<T> = {
success: true
data: T
message?: string
meta?: Record<string, unknown>
}
type ApiError = {
success: false
error: {
code: string
message: string
details?: unknown
}
}
npm install @0layimika/api-response-kit
yarn add @0layimika/api-response-kit
pnpm add @0layimika/api-response-kit
import { Ok, Created, NoContent } from "@0layimika/api-response-kit"
return Ok(user)
return Created(newUser)
return NoContent()
import { BadRequest, NotFound, Unauthorized } from "@olayimika/api-response-kit"
if (!user) return NotFound("User not found")
if (!email) return BadRequest("Email is required")
if (!token) return Unauthorized()
export function getUser(id: string) {
const user = findUser(id)
if (!user) {
return NotFound("User")
}
return Ok(user)
}
import { sendResponse } from "@0layimika/api-response-kit/express"
app.get("/users/:id", (req, res) => {
const response = getUser(req.params.id)
sendResponse(res, response)
})
import { CustomError } from "@0layimika/api-response-kit"
return CustomError({
code: "PAYMENT_FAILED",
status: 402,
message: "Payment authorization failed"
})
Download counts and popularity will appear here as the collector receives them.
| Package / target | Requirement | Relationship |
|---|---|---|
tsupEnvironment{
"local_name": "tsup",
"alias": false,
"peer_metadata": null
} | ^8.5.1 | runtime |
expressEnvironment{
"local_name": "express",
"alias": false,
"peer_metadata": null
} | ^5.2.1 | runtime |
fastifyEnvironment{
"local_name": "fastify",
"alias": false,
"peer_metadata": null
} | ^5.6.2 | runtime |
ts-nodeEnvironment{
"local_name": "ts-node",
"alias": false,
"peer_metadata": null
} | ^10.9.2 | development |
typescriptEnvironment{
"local_name": "typescript",
"alias": false,
"peer_metadata": null
} | ^5.9.3 | development |
@types/nodeEnvironment{
"local_name": "@types/node",
"alias": false,
"peer_metadata": null
} | ^25.0.3 | development |
@types/expressEnvironment{
"local_name": "@types/express",
"alias": false,
"peer_metadata": null
} | ^5.0.6 | development |
Source distribution
{
"shasum": "0cb0cd742a0fcaf6107d211e8596c0adef71b198",
"tarball": "https://registry.npmjs.org/@0layimika/api-response-kit/-/api-response-kit-0.1.2.tgz",
"fileCount": 38,
"integrity": "sha512-B/rQBkDpCTk+oPXncuRZMd7FRiEd5NMq/evh/p8vvmv6+JnBl9nPgio3OLA3zQFOqZkSQyh3W2fBEcBz7Vgm1g==",
"signatures": [
{
"sig": "MEUCIQCN5YqAkKJb9e6kkP5vObOfcGniSgFJZJA5GlUG44fVTQIgMn+CLx29wMDeA+vBB4p64SvP53ktew+dQ95qNwTfIvc=",
"keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"
}
],
"unpackedSize": 34967
}Observed since 20 Oct, 22:12 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:24979a29752eec2fcaebad82baa1811c59480eee96c8b4d1e8ae5e4632d1e4a5