0.1.2 • Published 7 months ago
@response/json v0.1.2
JSON Response
A class representing an JSON text response.
Installation
npm install @response/json
Usage
const json = require('@response/json')
const http = require('http')
http.createServer((req, res) => {
// Status 200
json({ status: 'success' }).write(res)
// Status 500
json(500, { status: 'error' }).write(res)
// Status 500 & custom headers
json(500, { status: 'error' }, { 'X-Powered-By': 'Foobar' }).write(res)
})
Mutable Properties
statusCode: number
- The status codeheaders: object
- The custom headersdata: object | object[]
- The JSON data to be stringified