npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@naman_deep_singh/http-response

v3.3.1

Published

TypeScript utilities for standardized API responses

Downloads

806

Readme

@naman_deep_singh/http-response

Version: 3.3.1

A flexible, framework-agnostic TypeScript response utility library for building consistent, typed, and configurable API responses.

Designed with a clean core + adapter architecture.
First-class support for Express.js, pagination, and standardized HTTP status handling.


🚀 Features

| Feature | Status | |---------------------------------------------|:------:| | Fully typesafe response envelopes | ✅ | | Framework-agnostic core | ✅ | | Express.js responder adapter | ✅ | | Express middleware injection | ✅ | | Pagination helpers | ✅ | | Centralized responder configuration | ✅ | | HTTP status constants | ✅ |


📦 Installation

npm install @naman_deep_singh/http-response

📄 Response Envelope (Default Shape)
interface ResponseEnvelope<P = unknown, M = Record<string, unknown>> {
  success: boolean
  message?: string
  data?: P
  error: {
    message: string
    code?: string
    details?: unknown
  } | null
  meta: M | null
}
🛠️ Usage
✔ Framework-Agnostic (No Express)
import { BaseResponder } from '@naman_deep_singh/http-response'

const responder = new BaseResponder()

const result = responder.ok({ user: 'John' }, 'Loaded')

// When no sender is attached, returns:
// { status: 200, body: ResponseEnvelope }
console.log(result)
🌐 Express Integration
1️⃣ Register Middleware
import express from 'express'
import { responderMiddleware } from '@naman_deep_singh/http-response'

const app = express()

app.use(responderMiddleware())
This injects a res.responder() factory into every request.

2️⃣ Controller Usage
app.get('/user', (req, res) => {
  const responder = res.responder<{ id: number; name: string }>()

  responder.okAndSend(
    { id: 1, name: 'John Doe' },
    'User found'
  )
})
✅ okAndSend() automatically:

sets HTTP status

sends JSON response

returns void for clean controller ergonomics

⚙️ Middleware Configuration
app.use(
  responderMiddleware({
    timestamp: true,
    extra: { service: 'user-service' },
  })
)
Example response:

{
  "success": true,
  "data": { ... },
  "error": null,
  "meta": {
    "timestamp": "2025-11-22T12:00:00Z"
  },
  "service": "user-service"
}
🔢 Pagination Support
responder.paginateAndSend(
  [{ id: 1 }],
  1,    // page
  10,   // limit
  42,   // total
  'Loaded'
)
Pagination metadata is automatically calculated.

📚 Available Methods
✅ Success Responses
Method	HTTP
ok()	200
created()	201
noContent()	204
paginate()	200
Each method has an Express variant:

okAndSend()

createdAndSend()

paginateAndSend()

❌ Error Responses
Method	HTTP
badRequest()	400
unauthorized()	401
forbidden()	403
notFound()	404
conflict()	409
unprocessableEntity()	422
tooManyRequests()	429
serverError()	500
Each also has a *AndSend() variant.

🧩 HTTP Status Constants
import { HTTP_STATUS } from '@naman_deep_singh/http-response'

HTTP_STATUS.SUCCESS.OK              // 200
HTTP_STATUS.CLIENT_ERROR.NOT_FOUND  // 404
HTTP_STATUS.SERVER_ERROR.INTERNAL_SERVER_ERROR // 500
Categories
SUCCESS

REDIRECTION

CLIENT_ERROR

SERVER_ERROR

✔ Object.freeze() protected
✔ Fully literal-typed (as const)
✔ IDE autocomplete friendly

🧩 TypeScript: Express Response Augmentation (Recommended)
For full type safety, add this once in your project:

import type { ExpressResponder } from '@naman_deep_singh/http-response'

declare global {
  namespace Express {
    interface Response {
      responder: <P = unknown>() => ExpressResponder<P>
    }
  }
}

⚠️ Do not use for new projects.

🔗 Integration with Other Packages
With @naman_deep_singh/server
import { responderMiddleware } from '@naman_deep_singh/http-response'

server.app.use(responderMiddleware())
With @naman_deep_singh/errors
import { expressErrorHandler } from '@naman_deep_singh/errors'

server.app.use(expressErrorHandler)
Provides consistent error responses across services.

🔜 Roadmap
Fastify adapter

Hono adapter

Configurable envelope key mapping

📄 License
MIT © Naman Deep Singh