[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Aug 9, 2020. It is now read-only.

kocisov/now-utilities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Utilities for serverless now^2.0

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published