1 | # http-response-object
|
2 |
|
3 | A simple object to represent an http response (with flow and typescript types)
|
4 |
|
5 | [](https://travis-ci.org/ForbesLindesay/http-response-object)
|
6 | [](https://david-dm.org/ForbesLindesay/http-response-object)
|
7 | [](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
|
17 | var Response = require('http-response-object');
|
18 | var 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'
|
23 | res.getBody();
|
24 | // => new Buffer('A ok')
|
25 |
|
26 | var 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'
|
31 | res.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
|