https://github.com/km-saifullah/quick-response
This is a npm package for sending api response in a particular format.
https://github.com/km-saifullah/quick-response
api api-response jaavscript nodejs npm npm-package quick-response
Last synced: 7 months ago
JSON representation
This is a npm package for sending api response in a particular format.
- Host: GitHub
- URL: https://github.com/km-saifullah/quick-response
- Owner: km-saifullah
- License: mit
- Created: 2024-08-12T15:52:00.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-30T16:41:19.000Z (over 1 year ago)
- Last Synced: 2025-06-12T13:48:39.022Z (8 months ago)
- Topics: api, api-response, jaavscript, nodejs, npm, npm-package, quick-response
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/quick-response
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# quick-response
API response message for any Node JS application



## Installation
Install the package in your project
```bash
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
```javascript
const apiResponse = require("quick-response");
console.log(apiResponse(200, "Success", { id: 1 }));
```
2. If you are using module js
```javascript
import apiResponse from "quick-response";
console.log(apiResponse(200, "Success", { id: 1 }));
```
**Response**
```javascript
{
statusCode: 200,
message: 'Success',
data: { id: 1 },
timestamp: 'Fri Aug 30 2024'
}
```
## Usage with Express
```javascript
import express from "express";
import apiResponse from "quick-response";
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"));
```
**Result**
```javascript
{
"statusCode": 201,
"message": "User Created",
"data": {
"id": 1,
"name": "John Doe"
},
"timestamp": "Fri Aug 30 2024"
}
```
Happy Coding...👍
## License
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.