0.3.1 • Published 7 years ago

now-utilities v0.3.1

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

now-utilities

Utilities for serverless now^2.0

Installation

# npm
$ npm install now-utilities

# yarn
$ yarn add now-utilities

Usage

import { handle } from 'now-utilities'

export default function(req, res) {
  handle(res)
    .setStatus(200)
    .json({
      status: 'success',
      message: 'Hello World!',
    })
}

API

body(request: http.IncomingMessage)

  • returns a Promise with parsed JSON body or null

handle(response: http.ServerResponse)

  • setStatus(code: number) => { .json(), .text(), ... }

  • json(response: http.ServerResponse) => (data: JSON) => null

    • sets status code to 200
    • sets Content-Type to application/json
    • prints out json
  • text(response: http.ServerResponse) => (data: string) => null

    • sets status code to 200
    • sets Content-Type to text/plain
    • prints out text
0.3.1

7 years ago

0.3.0

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago