@bbc/http-transport
A flexible, modular REST client built for ease-of-use and resilience.
Last updated 9 months ago by nspragg .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @bbc/http-transport 
SYNC missed versions from official npm registry.

NPM downloads Build Status npm license github-issues stars forks

http-transport

A flexible, modular REST client built for ease-of-use and resilience

Installation

npm install @bbc/http-transport --save

Usage

const url = 'http://example.com/';
const client = require('@bbc/http-transport').createClient();

const res = await client
   .get(url)
   .asResponse();
  
  if (res.statusCode === 200) {
    console.log(res.body);
  }

Documentation

For more examples and API details, see API documentation

TypeScript

Types are included in this project, and they also work with plugins.

Just pass the types that your plugin will add to context as a generic. This will be overlayed on top of any types added by previous plugins in the chain.

E.g.

const addSessionData: Plugin<{ session: { userId: string } } }> = (context, next) => {
  context.session = { userId: 'some-user' };
};

const res = await client
  .use(addSessionData)
  .use((context, next) => {
    if (context.session.userId === 'some-user') { // this would error if addSessionData middleware was missing
      // do something
    }
  })
  .use<{res: { random: number } }>((context, next) => {
    context.res.random = Math.random();
  })
  .get(url)
  .asResponse();

console.log(res.random); // number

Opting Out

If you don't want to type your plugin, simply use any as the type. This is not recomemnded though as it means all plugins later in the chain will loose the types too, because they have no idea what changes were made.

const myPlugin: Plugin<any> = (context, next) => {};

Test

npm test

To generate a test coverage report:

npm run coverage

Current Tags

  • 3.5.5                                ...           latest (9 months ago)

34 Versions

  • 3.5.5                                ...           9 months ago
  • 3.5.4                                ...           a year ago
  • 3.5.3                                ...           a year ago
  • 3.5.2                                ...           a year ago
  • 3.5.1                                ...           a year ago
  • 3.5.0                                ...           a year ago
  • 3.4.2                                ...           2 years ago
  • 3.4.1                                ...           2 years ago
  • 3.4.0                                ...           2 years ago
  • 3.3.0                                ...           2 years ago
  • 3.2.0                                ...           2 years ago
  • 3.1.1                                ...           2 years ago
  • 3.1.0                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.0.0                                ...           3 years ago
  • 0.0.18                                ...           3 years ago
  • 0.0.17                                ...           3 years ago
  • 0.0.16                                ...           3 years ago
  • 0.0.15                                ...           3 years ago
  • 0.0.14                                ...           3 years ago
  • 0.0.13                                ...           3 years ago
  • 0.0.11                                ...           3 years ago
  • 0.0.10                                ...           3 years ago
  • 0.0.9                                ...           3 years ago
  • 0.0.8                                ...           3 years ago
  • 0.0.7                                ...           3 years ago
  • 0.0.6                                ...           3 years ago
  • 0.0.5                                ...           3 years ago
  • 0.0.4                                ...           3 years ago
  • 0.0.3                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 34
Last Month 70
Dependencies (6)
Dev Dependencies (11)

Copyright 2014 - 2016 © taobao.org |