0.1.2 • Published 7 months ago

@response/json v0.1.2

Weekly downloads
28
License
MIT
Repository
github
Last release
7 months 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

7 months ago

0.1.1

4 years ago

0.1.0

4 years ago