1.0.4 • Published 11 months ago

quick-response v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

quick-response

API response message for any Node JS application

Node.js API JavaScript

Installation

Install the package in your project

npm quick-response

Usage

The package provides a utility function called apiResponse that allows you to create API response objects

The apiResponse function accepts the following parameters:

statusCode (number):

  • The HTTP status code to be returned with the response.
  • Example values: 200 (OK), 404 (Not Found), 500 (Internal Server Error).

message (string):

  • A brief message describing the response.
  • Example values: 'Success', 'Resource not found', 'Internal server error'.

data (object, optional):

  • An optional object containing additional data to be included in the response.
  • If not provided, the data field in the response will be set to null.
  • Example value: { id: 1, name: 'John Doe' }.
  1. If you are using common js
const apiResponse = require("quick-response");
console.log(apiResponse(200, "Success", { id: 1 }));
  1. If you are using module js
import apiResponse from "quick-response";
console.log(apiResponse(200, "Success", { id: 1 }));

Usage with Express

import express from "express";
import apiResponse from "apiResponse";

const app = express();
const port = 8000;

app.get("/", (req, res) => {
  res.json(apiResponse(201, "User Created", { id: 1, name: "John Doe" }));
});

app.listen(port, () => console.log("Server is running"));

Happy Coding...👍

License

This project is licensed under the MIT License - see the LICENSE file for details.

1.0.4

11 months ago

1.0.2

11 months ago

1.0.0

11 months ago