1.5.1 • Published 10 months ago
standard-http-response-js v1.5.1
Standard Http Response for server response
const express = require('express');
const { HttpResponse } = require('standard-http-response-js');
const app = express();
// response json data as usual it not informative
app.get('/', await (req, res, next) => {
const data = [] // retrive data from database
return res.json()
});
// response json data using 'standard-http-response-js'
app.get('/formatted-response', await (req, res, next) => {
const data = [] // retrive data from database
// more informative reponse
const response = HttpResponse.success({
payload: data,
statusCode: 11000 // <custom status code>,
version: 1,
})
//
//
// success() function return following json
// RESULT:
// {
// payload: '<data>'
// signature: '<hashed payload signature>'
// timestamp: '<IOS date string>',
// version: '<api version>',
// message: '<your custom message>',
// status: 'Succeed' | 'Failed',
// type: 'request' | 'OK' | 'heart-beat'
// }
//
//
// error() function return following json
// RESULT:
// {
// payload: null
// signature: '<hashed payload signature>'
// timestamp: '<IOS date string>',
// version: '<api version>',
// message: '<your custom message>',
// status: 'Succeed' | 'Failed',
// type: 'error',
// error: {
// status: '<error status>',
// message: '<error message>',
// errorMessage: '<error detailed message>',
// }
// }
//
//
return res.json(response)
})
app.listen(3000, () => {
const.log('server start listending on port 3000')
})
1.4.3
11 months ago
1.5.1
10 months ago
1.4.2
11 months ago
1.5.0
10 months ago
1.4.1
11 months ago
1.4.0
11 months ago
1.3.4
1 year ago
1.3.3
1 year ago
1.3.2
1 year ago
1.3.1
1 year ago
1.3.0
1 year ago
1.2.0
1 year ago
1.2.1
1 year ago
1.1.2
1 year ago
1.1.1
1 year ago
1.1.0
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