1.0.4 • Published 2 years ago

clean-response v1.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Clean-response

Description

This project help you to response your data from backend to frontend more clear.

Installation

$ npm install clean-response

How to Use

First you add project the file.

const SuccessResponse = require("clean-response")

You must give data and status code that you will return to frontend.There is example below.First field should be status code.SuccessResponse will understand which status code is used thus you can use all status code here.Second field should be data that you want to response to frontend.Finally you must call dataResult function.

var data = {
    name: "emin",
    surname: "oz",
    email: "example@gmail.com",
    contury: "turkey",
    hobbies: ["cooking", "learn new languages", "travel"],
};

const response = new SuccessResponse(201, data).dataResult()

Frontend will see this clean data.There are all information that frontend need such as data, status message, status code etc. Now frontend handle that data more easily.

{
  success: true,
  statusCode: 201,
  message: 'Created',
  data: {
    name: 'emin',
    surname: 'oz',
    email: 'example@gmail.com',
    country: 'turkey',
    hobbies: [ 'cooking', 'learn new languages', 'travel' ]
  }
}

Error Response

This packege use for error response as well.Here the example. Firstly ErrorResponse is added

const ErrorResponse = require("clean-response")

You can give all error status code and the call the dataResult function.

const response = new ErrorResponse(400).dataResult()

Frontend will see this clean data.

{ success: false, statusCode: 400, message: 'Bad Request' }
1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago