# responsify-requests

> This package will help you throw the response messages along with the proper status code and proper structure.

Latest version **1.0.9** (published 2023-03-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install responsify-requests
pnpm add responsify-requests
yarn add responsify-requests
bun add responsify-requests
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2023-03-24 |
| First published | 2023-03-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dharm Joshi |
| Maintainers | dharmopenxcell |
| Keywords | response, response-generator, http-response-message |

## Links

- npm: https://www.npmjs.com/package/responsify-requests
- npm.io page: https://npm.io/package/responsify-requests

## Recent versions

- 1.0.9 (latest) — 2023-03-24
- 1.0.8 — 2023-03-23
- 1.0.7 — 2023-03-16
- 1.0.6 — 2023-03-16
- 1.0.5 — 2023-03-16
- 1.0.4 — 2023-03-16
- 1.0.3 — 2023-03-16
- 1.0.2 — 2023-03-16
- 1.0.1 — 2023-03-16
- 1.0.0 — 2023-03-16

## README

# responsify-requests

A small-sized library for handling the response of your APIs, in a well structured way.
This library will form a response to your api by having some parameters in function call.



## Installation

Install this package with npm

```bash
 $ npm install responsify-requests
```
    
## Parameters


| Parameter | Type     | Description                |
| :-------- | :------- | :------------------------- |
| `res` | `object` | **Required**. Response object of your api. |
| `data` | `object` | **Required**. Data to show on success. |
| `status` | `number` | **Required**. Status of your response (0 on failure and 1 on success). |
| `message` | `string` | **Required**. Certain message to show on api call. |
| `response` | `string` | **Required**. Allowed Values      [SUCCESS], [UNAUTHORIZED], [NOT_FOUND], [BAD_REQUEST], [TOO_MANY_REQUESTS], [UNPROCESSABLE_ENTITY] |


## Status codes

| response (parameter) | Status Code | 
| :------------------- | :---------  |
| `SUCCESS` | 200 |
| `UNAUTHORIZED` | 401 |
| `NOT_FOUND` | 404 |
| `BAD_REQUEST` | 400 |
| `TOO_MANY_REQUESTS` | 429 |
| `UNPROCESSABLE_ENTITY` | 422 |

## Note

If you do not pass any response parameter to method, Then it will consider as "Internal Server Error" with status code of 500.

## Usage/Examples

```javascript
const response = require('responsify-requests');

app.get('your_url', (req,res)=> {
    try {
    
    // if you want to send this data as response...

        let data = {
            id: 1,
            name: "XYZ"
        }
        return response(res, data, 1, "Data recieved succesfully", "SUCCESS");
    } catch (e) {
        return response(res, {}, 0, "Error occured", "BAD_REQUEST");
    }
})
```

## Output Format

Success Response

```json
{
    "message" : "Data recieved succesfully",
    "data" : {
        "id": 1,
        "name": "XYZ"
    },
    "status": 1
}
```

Failure Response

```json
{
    "message" : "Error occured",
    "status": 0
}
```

---
_Source: https://npm.io/package/responsify-requests · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
