Catalog npm
Back to packageRELEASE DETAILS

0.1.0

npm

@0layimika/api-response-kit

A typed toolkit for consistent API success and error responses

apiapi-responseapi-toolkitdeveloper-toolserror-handlingexpressfastifyhttpnestjsrestsuccess-responsetypescript
Published3 Jan 2026
Direct dependencies7
Transitive dependenciesNot calculated

README

Current package documentation

api-response-kit

A small, TypeScript-first toolkit for consistent API success and error responses.


Why This Exists

Most APIs suffer from the same problems:

  • Inconsistent response shapes across endpoints
  • Ad-hoc error handling (throw new Error, random JSON)
  • Frontend has to guess response structures
  • Documentation drifts away from reality
  • Boilerplate res.status().json() everywhere

api-response-kit fixes this by enforcing a predictable response contract for both success and error responses while keeping your code clean and framework-agnostic.


Core Idea

Instead of:

res.status(200).json(user)
res.status(400).json({ error: "Invalid input" })

You write:

return Ok(user)
return BadRequest("Invalid input")

Response Contract

Success Response

type ApiSuccess<T> = {
  success: true
  data: T
  message?: string
  meta?: Record<string, unknown>
}

Error Response

type ApiError = {
  success: false
  error: {
    code: string
    message: string
    details?: unknown
  }
}

Installation

npm install @0layimika/api-response-kit

yarn add @0layimika/api-response-kit

pnpm add @0layimika/api-response-kit

Basic Usage

Success Helpers

import { Ok, Created, NoContent } from "@0layimika/api-response-kit"

return Ok(user)
return Created(newUser)
return NoContent()

Error Helpers

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()

Controller Example

export function getUser(id: string) {
  const user = findUser(id)

  if (!user) {
    return NotFound("User")
  }

  return Ok(user)
}

Express Adapter Example

import { sendResponse } from "@0layimika/api-response-kit/express"

app.get("/users/:id", (req, res) => {
  const response = getUser(req.params.id)
  sendResponse(res, response)
})

Custom Errors

import { CustomError } from "@0layimika/api-response-kit"

return CustomError({
  code: "PAYMENT_FAILED",
  status: 402,
  message: "Payment authorization failed"
})

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 7

Native requirements
7 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
tsup
Environment
{
  "local_name": "tsup",
  "alias": false,
  "peer_metadata": null
}
^8.5.1runtime
express
Environment
{
  "local_name": "express",
  "alias": false,
  "peer_metadata": null
}
^5.2.1runtime
fastify
Environment
{
  "local_name": "fastify",
  "alias": false,
  "peer_metadata": null
}
^5.6.2runtime
ts-node
Environment
{
  "local_name": "ts-node",
  "alias": false,
  "peer_metadata": null
}
^10.9.2development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^5.9.3development
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
^25.0.3development
@types/express
Environment
{
  "local_name": "@types/express",
  "alias": false,
  "peer_metadata": null
}
^5.0.6development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "428b8f41b950a66246eeb44a3d7cc28b935d5e61",
  "tarball": "https://registry.npmjs.org/@0layimika/api-response-kit/-/api-response-kit-0.1.0.tgz",
  "fileCount": 38,
  "integrity": "sha512-VasFfN4eLOXving3RfPq3B1c7Uq0OoHRUaY5c9SVFjLrRLa5hXHXqFwApzhasP61ksouimrARbY50cH2zlI0fA==",
  "signatures": [
    {
      "sig": "MEQCIERm3mAPBQsMxI42eOIFfQLmg8JV9Qiy+kw3fDaUEA3fAiBuZddvCUnqfNLUq6IFyiij91YWiPq8TJh0bEud/RbFwA==",
      "keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"
    }
  ],
  "unpackedSize": 34665
}

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:12 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:e97f0e993e1bf80decd85ce5755e477dfe0a6ba6b0e8531d85b5fe1cf736e60d

Other collected versions

0.1.34 Jan0.1.23 Jan0.1.13 JanView all collected versions →