Success replies
Wrap route results with ok() so every successful payload follows the same shape.
Standard API responses for Node.js
replyify gives your backend one clean response format for success, errors, validation, and pagination so frontend code and SDKs stop guessing.
import { ok, apiError, paginate } from "@ironstack/replyify"
return ok(user)
throw apiError("NOT_FOUND", "User not found")
return paginate(users, { page: 1, limit: 10, total: 42 })
Problem
Teams start simple, then every route returns a slightly different JSON shape. Errors become inconsistent, pagination changes per endpoint, and frontend consumers need special-case logic.
res.json(data)
res.status(400).json({ error })
throw new Error()
Solution
replyify centralizes reply building, error normalization, status mapping, and Express integration while keeping the core framework agnostic.
return ok(user)
throw apiError("NOT_FOUND", "User not found")
return paginate(users, { page, limit, total })
Before / After
app.get("/users", async (req,res)=>{
res.json(users)
})
app.get(
"/users",
replyHandler(async ()=>{
return ok(users)
})
)
Install
Install the package, then import the helpers you need from the root entry point or the Express subpath.
npm install @ironstack/replyify
Usage
Wrap route results with ok() so every successful payload follows the same shape.
Use fail() for non-throwing errors and apiError() when you want to throw.
Use paginate() to attach page, limit, total, and pages in one consistent meta block.
Examples
API
Build a success reply result.
Build an error reply result without throwing.
Build a paginated reply result with pagination metadata.
Create an ApiError instance.
Create a validation error reply result.
Error class with code, status, errors, and meta.
Express wrapper that formats returned reply results automatically.
Express middleware for normalizing and formatting thrown errors.