npm.io
0.6.0-beta.6 • Published 5 years ago

@burstjs/http

Licence
Apache-2.0
Version
0.6.0-beta.6
Deps
1
Size
224 kB
Vulns
23
Weekly
0
Stars
97
DeprecatedThis package is deprecated

@burstjs/http

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

Installation

@burstjs/http can be used with NodeJS or Web. Two formats are available

Using with NodeJS and/or modern web frameworks

Install using npm:

npm install @burstjs/http

or using yarn:

yarn add @burstjs/http
Example
import {HttpImpl} from '@burstjs/http'

try{
    const client = new HttpImpl('https://jsonplaceholder.typicode.com/');
    const response = client.get('/todos/1')
    console.log(response)
}
catch(httpError){
    console.error(httpError.message)
}
Using in classic <script>

Each package is available as bundled standalone library using IIFE. This way burstJS can be used also within <script>-Tags. This might be useful for Wordpress and/or other PHP applications.

Just import the package using the HTML <script> tag.

<script src='https://cdn.jsdelivr.net/npm/@burstjs/http/dist/burstjs.http.min.js'></script>

Example
const client = new b$http.HttpImpl('https://jsonplaceholder.typicode.com/');
client.get('/todos/1').then(console.log)

See more here:

@burstjs/http Online Documentation


API Reference

Modules

http

HttpError class

Thrown on HTTP errors

http

Http Implementation of [[Http]] using https://github.com/axios/axios

You can use [[HttpClient]] as alias

http http

Http Mocker Builder for easy to http testing

Example:

 const mockedHttp = HttpMockBuilder
 .create()
 .onGetReply(200, {foo: 'get'})
 .onPostThrowError(500, 'Post Error', {e: 'post'})
 .onPutThrowError(404, 'Put Error', {e: 'put'})
 .onDeleteThrowError(403, 'Delete Error', {e: 'delete'})
 .build();

const response = await mockedHttp.get('/url');

await mockedHttp.post('/url/post', {faz: 'post'}); // will throw exception

http

Http Response

Returned by Http request

http

Alias for HttpImpl

http

HttpError class

Thrown on HTTP errors

http~HttpImpl

Kind: inner class of http

new HttpImpl(baseURL, options)

Creates your Http client

Param Description
baseURL

The baseUrl, i.e host url

options

[optional] An options/configurations object applied to all requests The current implementation uses axios, so the options can be found here Axios Configuration

HttpImpl.mountError(url, error)

Kind: static method of HttpImpl
Internal:

Param Description
url

The url

error

The returned error

http

Http Implementation of [[Http]] using https://github.com/axios/axios

You can use [[HttpClient]] as alias

http~HttpImpl

Kind: inner class of http

new HttpImpl(baseURL, options)

Creates your Http client

Param Description
baseURL

The baseUrl, i.e host url

options

[optional] An options/configurations object applied to all requests The current implementation uses axios, so the options can be found here Axios Configuration

HttpImpl.mountError(url, error)

Kind: static method of HttpImpl
Internal:

Param Description
url

The url

error

The returned error

http

Internal: 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

http~HttpImpl

Kind: inner class of http

new HttpImpl(baseURL, options)

Creates your Http client

Param Description
baseURL

The baseUrl, i.e host url

options

[optional] An options/configurations object applied to all requests The current implementation uses axios, so the options can be found here Axios Configuration

HttpImpl.mountError(url, error)

Kind: static method of HttpImpl
Internal:

Param Description
url

The url

error

The returned error

http

Http Mocker Builder for easy to http testing

Example:

 const mockedHttp = HttpMockBuilder
 .create()
 .onGetReply(200, {foo: 'get'})
 .onPostThrowError(500, 'Post Error', {e: 'post'})
 .onPutThrowError(404, 'Put Error', {e: 'put'})
 .onDeleteThrowError(403, 'Delete Error', {e: 'delete'})
 .build();

const response = await mockedHttp.get('/url');

await mockedHttp.post('/url/post', {faz: 'post'}); // will throw exception

http~HttpImpl

Kind: inner class of http

new HttpImpl(baseURL, options)

Creates your Http client

Param Description
baseURL

The baseUrl, i.e host url

options

[optional] An options/configurations object applied to all requests The current implementation uses axios, so the options can be found here Axios Configuration

HttpImpl.mountError(url, error)

Kind: static method of HttpImpl
Internal:

Param Description
url

The url

error

The returned error

http

Http Response

Returned by Http request

http~HttpImpl

Kind: inner class of http

new HttpImpl(baseURL, options)

Creates your Http client

Param Description
baseURL

The baseUrl, i.e host url

options

[optional] An options/configurations object applied to all requests The current implementation uses axios, so the options can be found here Axios Configuration

HttpImpl.mountError(url, error)

Kind: static method of HttpImpl
Internal:

Param Description
url

The url

error

The returned error

http

Alias for HttpImpl

http~HttpImpl

Kind: inner class of http

new HttpImpl(baseURL, options)

Creates your Http client

Param Description
baseURL

The baseUrl, i.e host url

options

[optional] An options/configurations object applied to all requests The current implementation uses axios, so the options can be found here Axios Configuration

HttpImpl.mountError(url, error)

Kind: static method of HttpImpl
Internal:

Param Description
url

The url

error

The returned error