@bbc/http-transport
Advanced tools
Comparing version 0.0.7 to 0.0.8
52
docs.md
@@ -9,10 +9,2 @@ # HttpTranport | ||
The example below prints all of the files in a directory that have the `.json` file extension: | ||
```js | ||
const httpTransport = require('http-transport'); | ||
``` | ||
#### Supported HTTP methods | ||
@@ -44,2 +36,4 @@ | ||
PATCH, DELETE, HEAD are also supported. | ||
#### Query strings | ||
@@ -49,2 +43,3 @@ | ||
Single query string | ||
```js | ||
@@ -61,2 +56,18 @@ const url = 'http://example.com/'; | ||
Multiple query strings: | ||
```js | ||
const url = 'http://example.com/'; | ||
HttpTransport.createClient() | ||
.get(url) | ||
.query({ | ||
example1: true | ||
example2: false | ||
}) | ||
.asResponse() | ||
.then((res) => { | ||
console.log(res); | ||
}); | ||
``` | ||
#### Headers | ||
@@ -66,5 +77,17 @@ | ||
Add a single header: | ||
```js | ||
HttpTransport.createClient() | ||
.get(url) | ||
.headers('someHeader1', 'someValue1') | ||
.asResponse() | ||
.then((res) => { | ||
console.log(res); | ||
}); | ||
``` | ||
Add multiple headers: | ||
```js | ||
HttpTransport.createClient() | ||
.get(url) | ||
.headers({ | ||
@@ -85,3 +108,3 @@ 'someHeader1' : 'someValue1' | ||
```js | ||
const toError = require('http-transport-to-errors'); | ||
const toError = require('@bbc/http-transport-to-error'); | ||
@@ -99,2 +122,5 @@ const url = 'http://example.com/'; | ||
`toError` is only required if the underlying client does not support HTTP error conversion. | ||
The default transport is `request`, which does not convert errors. | ||
#### Retries | ||
@@ -105,3 +131,3 @@ | ||
```js | ||
const toError = require('http-transport-to-errors'); | ||
const toError = require('@bbc/http-transport-to-error'); | ||
@@ -136,6 +162,6 @@ return HttpTransport.createClient() | ||
const url = 'http://example.com/'; | ||
const HttpTransport = require('http-transport'); | ||
const Wreck = require('http-transport-wreck'); | ||
const HttpTransport = require('@bbc/http-transport'); | ||
const OtherTranport = require('some-other-transport'); | ||
HttpTransport.createClient(Wreck) | ||
HttpTransport.createClient(OtherTranport) | ||
.get(url) | ||
@@ -142,0 +168,0 @@ .asResponse() |
@@ -112,3 +112,3 @@ 'use strict'; | ||
* @method | ||
* post | ||
* put | ||
* @param {string} url | ||
@@ -136,3 +136,3 @@ * @param {object} request body | ||
* @method | ||
* post | ||
* delete | ||
* @param {string} url | ||
@@ -159,3 +159,3 @@ * @param {object} request body | ||
* @method | ||
* post | ||
* patch | ||
* @param {string} url | ||
@@ -373,6 +373,6 @@ * @param {object} request body | ||
function isCriticalError(err) { | ||
if (err && (!err.statusCode || err.statusCode >= 500)) { | ||
return true; | ||
if (err && err.statusCode < 500) { | ||
return false; | ||
} | ||
return false; | ||
return true; | ||
} | ||
@@ -379,0 +379,0 @@ |
'use strict'; | ||
const REQUIRED_PROPERTIES = [ | ||
'url', | ||
'body', | ||
'status', | ||
'headers', | ||
'elapsedTime' | ||
'url', | ||
'body', | ||
'statusCode', | ||
'headers', | ||
'elapsedTime' | ||
]; | ||
@@ -16,3 +16,3 @@ | ||
this.url; | ||
this.status; | ||
this.statusCode; | ||
this.body; | ||
@@ -52,3 +52,3 @@ } | ||
headers: this.headers, | ||
status: this.status | ||
statusCode: this.statusCode | ||
}; | ||
@@ -55,0 +55,0 @@ } |
{ | ||
"name": "@bbc/http-transport", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "A flexible, modular REST client built for ease-of-use and resilience.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,3 +10,3 @@ [![Build Status](https://travis-ci.org/bbc/http-transport.svg)](https://travis-ci.org/bbc/http-transport) [![Coverage Status](https://coveralls.io/repos/github/bbc/http-transport/badge.svg?branch=master)](https://coveralls.io/github/bbc/http-transport?branch=master) | ||
``` | ||
npm install --save http-transport | ||
npm install @bbc/http-transport --save | ||
``` | ||
@@ -18,3 +18,3 @@ | ||
const url = 'http://example.com/'; | ||
const client = require('http-transport').createClient(); | ||
const client = require('@bbc/http-transport').createClient(); | ||
@@ -29,3 +29,2 @@ client | ||
}); | ||
}); | ||
``` | ||
@@ -32,0 +31,0 @@ |
@@ -9,3 +9,3 @@ const assert = require('assert'); | ||
body: 'body content', | ||
status: 200 | ||
statusCode: 200 | ||
}; | ||
@@ -15,3 +15,3 @@ | ||
assert.equal(response.url, properties.url); | ||
assert.equal(response.status, properties.status); | ||
assert.equal(response.statusCode, properties.statusCode); | ||
assert.equal(response.body, properties.body); | ||
@@ -93,3 +93,3 @@ }); | ||
body: 'body content', | ||
status: 200, | ||
statusCode: 200, | ||
elapsedTime: 10 | ||
@@ -96,0 +96,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
403637
43