Skip to content

Commit

Permalink
Task: Update docs for async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
nspragg committed Feb 22, 2018
1 parent 7dd9646 commit d56a7d2
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,43 @@ npm install --save http-transport-cache
Configure response caching based on max-age:

```js
const url = 'http://example.com/';
const HttpTransport = require('http-transport');
const bluebird = require('bluebird');
const cache = require('@bbc/http-transport-cache');
const Catbox = require('catbox');
const HttpTransport = require('@bbc/http-transport');

const catbox = new Catbox.Client(new Memory());

const cache = new Catbox.Client(new Memory());
bluebird.promisifyAll(cache);
const url = 'http://example.com/';

const client = HttpTransport.createBuilder()
.use(cache.maxAge(catbox))
.createClient();

client.get(url)
.asBody()
.then((body) => {
console.log(body);
});
const body = await client.get(url)
.asBody();

console.log(body);
```

Configure stale-if-error:

```js
const url = 'http://example.com/';
const HttpTransport = require('http-transport');
const bluebird = require('bluebird');
const cache = require('@bbc/http-transport-cache');
const Catbox = require('catbox');
const HttpTransport = require('@bbc/http-transport');

const catbox = new Catbox.Client(new Memory());

const cache = new Catbox.Client(new Memory());
bluebird.promisifyAll(cache);
const url = 'http://example.com/';

const client = HttpTransport.createClient()
.use(cache.staleIfError(catbox))
.createClient();

client.get(url)
.asBody()
.then((body) => {
console.log(body);
});
const body = await client.get(url)
.asBody();

console.log(body);
```

## Features
Expand Down

0 comments on commit d56a7d2

Please sign in to comment.