UNPKG

1.71 kBMarkdownView Raw
1# http-response-object
2
3A simple object to represent an http response (with flow and typescript types)
4
5[![Build Status](https://img.shields.io/travis/ForbesLindesay/http-response-object/master.svg)](https://travis-ci.org/ForbesLindesay/http-response-object)
6[![Dependency Status](https://img.shields.io/david/ForbesLindesay/http-response-object.svg)](https://david-dm.org/ForbesLindesay/http-response-object)
7[![NPM version](https://img.shields.io/npm/v/http-response-object.svg)](https://www.npmjs.org/package/http-response-object)
8
9
10## Installation
11
12 npm install http-response-object
13
14## Usage
15
16```js
17var Response = require('http-response-object');
18var res = new Response(200, {}, new Buffer('A ok'), 'http://example.com');
19//res.statusCode === 200
20//res.headers === {}
21//res.body === new Buffer('A ok')
22//res.url === 'http://example.com'
23res.getBody();
24// => new Buffer('A ok')
25
26var res = new Response(404, {'Header': 'value'}, new Buffer('Wheres this page'), 'http://example.com');
27//res.statusCode === 404
28//res.headers === {header: 'value'}
29//res.body === new Buffer('Wheres this page')
30//res.url === 'http://example.com'
31res.getBody();
32// => throws error with `statusCode`, `headers`, `body` and `url` properties copied from the response
33```
34
35## Properties
36
37 - `statusCode`: Number - the status code of the response
38 - `headers`: Object - the headers of the response. The keys are automatically made lower case.
39 - `body`: Buffer | String - the body of the response. Should be a buffer on the server side, but may be a simple string for lighter weight clients.
40 - `url`: String - the url that was requested. If there were redirects, this should be the last url to get requested.
41
42## License
43
44 MIT