npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

@burstjs/http

0.1.0-rc.3.2 • Public • Published

@burstjs/http

Generic HTTP client that is used as a network provider for @burst/core.

Installation

Install using npm:

npm install @burstjs/http

or using yarn:

yarn add @burstjs/http

API Reference

Classes

HttpError

HttpError class

Thrown on HTTP errors

HttpImpl
HttpMock

Http Mocker for easy to http testing using Jest

When using this mocking helper you need to call Http.onGet() before Http instance is created

HttpError

HttpError class

Thrown on HTTP errors

Kind: global class

HttpImpl

Kind: global class

new HttpImpl(baseURL)

Creates your Http client

Param Description
baseURL

The baseUrl, i.e host url

HttpMock

Http Mocker for easy to http testing using Jest

When using this mocking helper you need to call Http.onGet() before Http instance is created

Kind: global class

HttpMock.onGet(endpoint?)

Mocks responses for get methods You may pass a specific endpoint as parameter to mock only selected endpoints. This is very useful, when having methods that do several Http requests, so you can mock them one on one.

The following code returns the same content on every get call

  HttpMock.onGet().reply(200, [{login: 'foo'}, {login: 'bar'}]);

The next code returns the different content depending on the passed endpoint

  HttpMock.onGet('/foo').reply(200, {data: 'foo'});
  HttpMock.onGet('/bar').reply(200, {data: 'bar'});

Kind: static method of HttpMock

Param Description
endpoint?

An endpoint, to allow specific behavior on that endpoint

HttpMock.onPost(endpoint?)

Mocks responses for post methods

Kind: static method of HttpMock

Param Description
endpoint?

An endpoint, to allow specific behavior on that endpoint

HttpMock.onPut(endpoint?)

Mocks responses for put methods

Kind: static method of HttpMock

Param Description
endpoint?

An endpoint, to allow specific behavior on that endpoint

HttpMock.onDelete(endpoint?)

Mocks responses for delete methods

Kind: static method of HttpMock

Param Description
endpoint?

An endpoint, to allow specific behavior on that endpoint

HttpMock.reset()

Resets all mocked behavior

Kind: static method of HttpMock

Keywords

none

install

npm i @burstjs/http

Downloadsweekly downloads

204

version

0.1.0-rc.3.2

license

GPL-3.0

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
Report a vulnerability