now-utilities
v0.3.1
Published
Utilities for serverless now^2.0
Downloads
4
Readme
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
to200
- sets
Content-Type
toapplication/json
- prints out json
- sets
text(response: http.ServerResponse) => (data: string) => null
- sets
status code
to200
- sets
Content-Type
totext/plain
- prints out text
- sets