0.1.2 • Published 2 years ago

@response/json v0.1.2

Weekly downloads
28
License
MIT
Repository
github
Last release
2 years ago

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 code
  • headers: object - The custom headers
  • data: object | object[] - The JSON data to be stringified
0.1.2

2 years ago

0.1.1

5 years ago

0.1.0

5 years ago