1.3.4 • Published 1 month ago

standard-http-response-js v1.3.4

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

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.3.4

1 month ago

1.3.3

1 month ago

1.3.2

1 month ago

1.3.1

1 month ago

1.3.0

1 month ago

1.2.0

2 months ago

1.2.1

2 months ago

1.1.2

3 months ago

1.1.1

3 months ago

1.1.0

3 months ago

1.0.3

3 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago