1.0.9 • Published 1 year ago

responsify-requests v1.0.9

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

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

 $ npm install responsify-requests

Parameters

ParameterTypeDescription
resobjectRequired. Response object of your api.
dataobjectRequired. Data to show on success.
statusnumberRequired. Status of your response (0 on failure and 1 on success).
messagestringRequired. Certain message to show on api call.
responsestringRequired. Allowed Values SUCCESS, UNAUTHORIZED, NOT_FOUND, BAD_REQUEST, TOO_MANY_REQUESTS, UNPROCESSABLE_ENTITY

Status codes

response (parameter)Status Code
SUCCESS200
UNAUTHORIZED401
NOT_FOUND404
BAD_REQUEST400
TOO_MANY_REQUESTS429
UNPROCESSABLE_ENTITY422

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

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

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

Failure Response

{
    "message" : "Error occured",
    "status": 0
}
1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago