Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

responzo

pratikghelani8MIT1.0.3

responzo is a Node.js utility package designed to simplify response handling in API applications. It provides a set of predefined response structures for various HTTP status codes, making it easy to format consistent API responses for both success and err

response, handler, API, utility, nodejs, express, response-handler, api-response, error-handling, success-response, http-response, api-error, validation-error, status-code, response-utility, rate-limit, server-error, unauthorized, forbidden, conflict, not-found, bad-request, validation, http-status, response-format, error-codes, custom-error, response-json, api-helper

readme

responzo

responzo is a Node.js utility package designed to simplify response handling in API applications. It provides a set of predefined response structures for various HTTP status codes, making it easy to format consistent API responses for both success and error cases.


Benefits of Using responzo

  • Consistency: Standardize response structures across your application for both success and error scenarios.
  • Simplicity: Reduce boilerplate code and improve code clarity by using pre-defined response formats.
  • Time-Saving: Save time when dealing with common response patterns, focusing on building features instead of handling responses.

Installation

To get started with responzo, follow the steps below.

Install the Package

You can install responzo via npm. In your project directory, run the following command:

npm install responzo 

Usage

Import ResponseHandler

const ResponseHandler = require('responzo');

Response Handler

Success Response

app.get('/success', (req, res) => {
  return res.status(200).json(ResponseHandler.success("Data fetched successfully", { id: 1, name: "John Doe" }));
});

Created Response

app.post('/created', (req, res) => {
  return res.status(201).json(ResponseHandler.created("Resource created successfully", { userId: 123 }));
});

Bad Request Response

app.get('/bad-request', (req, res) => {
  return res.status(400).json(ResponseHandler.badRequest("Invalid request", { missing: "name" }));
});

Validation Errort Response

app.get('/validation-error', (req, res) => {
  return res.status(422).json(ResponseHandler.validationError({ email: "Invalid email format" }));
});

Unauthorized

app.get('/unauthorized', (req, res) => {
  return res.status(401).json(ResponseHandler.unauthorized());
});

Forbidden

app.get('/forbidden', (req, res) => {
  return res.status(403).json(ResponseHandler.forbidden("Access denied"));
});

Not Found

app.get('/not-found', (req, res) => {
  return res.status(404).json(ResponseHandler.notFound("Resource not found"));
});

Conflict

app.get('/conflict', (req, res) => {
  return res.status(409).json(ResponseHandler.conflict("Conflict occurred"));
});

Server Error

app.get('/server-error', (req, res) => {
  return res.status(500).json(ResponseHandler.serverError("Internal Server Error"));
});

Too Many Requests

app.get('/too-many-requests', (req, res) => {
  return res.status(429).json(ResponseHandler.tooManyRequests());
});

🔗 Connect with Pratikkumar Ghelani

Expert in Node.js, React, Next.js, Express.js, MongoDB, MySQL, AWS, AI & ML, Android & iOS | SaaS | Delivering Scalable, High-Performance Applications | Custom Software Solutions Specialist

linkedin

Buy Me a Coffee

"Buy Me A Coffee"