Utilities for serverless now^2.0
# npm
$ npm install now-utilities
# yarn
$ yarn add now-utilities
import { handle } from 'now-utilities'
export default function(req, res) {
handle(res)
.setStatus(200)
.json({
status: 'success',
message: 'Hello World!',
})
}
- returns a Promise with parsed JSON body or null
-
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