Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@burstjs/http

Package Overview
Dependencies
Maintainers
2
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@burstjs/http

Send commands to BURST over HTTP

  • 0.5.0-beta.12
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-50%
Maintainers
2
Weekly downloads
 
Created
Source

@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

Classes

HttpImpl

Generic Http client

http

http~HttpError

HttpError class

Thrown on HTTP errors

Kind: inner class of http

http~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: inner class of http

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

ParamDescription
endpoint?

An endpoint, to allow specific behavior on that endpoint

HttpMock.onPost(endpoint?)

Mocks responses for post methods

Kind: static method of HttpMock

ParamDescription
endpoint?

An endpoint, to allow specific behavior on that endpoint

HttpMock.onPut(endpoint?)

Mocks responses for put methods

Kind: static method of HttpMock

ParamDescription
endpoint?

An endpoint, to allow specific behavior on that endpoint

HttpMock.onDelete(endpoint?)

Mocks responses for delete methods

Kind: static method of HttpMock

ParamDescription
endpoint?

An endpoint, to allow specific behavior on that endpoint

HttpMock.reset()

Resets all mocked behavior

Kind: static method of HttpMock

http~HttpResponse

Http Response

Returned by Http request

Kind: inner class of http

http

http~HttpError

HttpError class

Thrown on HTTP errors

Kind: inner class of http

http~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: inner class of http

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

ParamDescription
endpoint?

An endpoint, to allow specific behavior on that endpoint

HttpMock.onPost(endpoint?)

Mocks responses for post methods

Kind: static method of HttpMock

ParamDescription
endpoint?

An endpoint, to allow specific behavior on that endpoint

HttpMock.onPut(endpoint?)

Mocks responses for put methods

Kind: static method of HttpMock

ParamDescription
endpoint?

An endpoint, to allow specific behavior on that endpoint

HttpMock.onDelete(endpoint?)

Mocks responses for delete methods

Kind: static method of HttpMock

ParamDescription
endpoint?

An endpoint, to allow specific behavior on that endpoint

HttpMock.reset()

Resets all mocked behavior

Kind: static method of HttpMock

http~HttpResponse

Http Response

Returned by Http request

Kind: inner class of http

http

http~HttpError

HttpError class

Thrown on HTTP errors

Kind: inner class of http

http~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: inner class of http

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

ParamDescription
endpoint?

An endpoint, to allow specific behavior on that endpoint

HttpMock.onPost(endpoint?)

Mocks responses for post methods

Kind: static method of HttpMock

ParamDescription
endpoint?

An endpoint, to allow specific behavior on that endpoint

HttpMock.onPut(endpoint?)

Mocks responses for put methods

Kind: static method of HttpMock

ParamDescription
endpoint?

An endpoint, to allow specific behavior on that endpoint

HttpMock.onDelete(endpoint?)

Mocks responses for delete methods

Kind: static method of HttpMock

ParamDescription
endpoint?

An endpoint, to allow specific behavior on that endpoint

HttpMock.reset()

Resets all mocked behavior

Kind: static method of HttpMock

http~HttpResponse

Http Response

Returned by Http request

Kind: inner class of http

HttpImpl

Generic Http client

Kind: global class

new HttpImpl(baseURL, options)

Creates your Http client

ParamDescription
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

FAQs

Package last updated on 26 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc