json-response-builder
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

json-response-builder

This package helps to build json response from server side. This will be specially helpfull in serverless environments.

Installation

npm i json-response-builder

Simple Usage

import {res} from "json-response-builder"

# returns a json body
return res.json({
          "key":"value" //JSON BODY HERE
       })

This would output a response as bellow

 {
  headers: { 'content-type': 'application/json' },
  statusCode: 400,
  isBase64Encoded: false,
  body: '{"key":"value"}'
 }

Options

Can include additional headers and options as below

import {res} from "json-response-builder"

  res
    .json({
        "key": "value",
     })
    .headers({
        "headerKey":"headerValue"
    })
    .gzip() //apply gzip compression
    .statusCode(400)
    .build()

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

/json-response-builder/

    Package Sidebar

    Install

    npm i json-response-builder

    Weekly Downloads

    48

    Version

    1.0.9

    License

    MIT

    Unpacked Size

    10.5 kB

    Total Files

    12

    Last publish

    Collaborators

    • asce4s