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

bivrost-axios-adapter

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bivrost-axios-adapter

Bivrost adapter for axios

  • 3.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24
increased by242.86%
Maintainers
1
Weekly downloads
 
Created
Source

Bivrost axios adapter

Build Status NPM Version

Bivrost Adapter for axios function.

npm i --save axios bivrost-axios-adapter

Usage

With Bivrost:

import DataSource from 'bivrost/data/source';
import bivrostApi from 'bivrost/http/api';
import axiosAdapter from 'bivrost-axios-adapter';

const api = bivrostApi({
  host: 'localhost',
  adapter: axiosAdapter(),
});

class UsersDataSource extends DataSource {
  static api = {
    loadAll: api('GET /users'),
  };

  loadUsers(filters) {
    return this.invoke('loadAll', filters);
  }
}

Direct calls:

import axiosAdapter from 'bivrost-axios-adapter';

const api = axiosAdapter({});

const options = {
  method: 'GET',
  query: {
    groupId: 10,
  },
  headers: {
    'Content-Type': 'application/json',
  },
};

api('/users', options)
  .then(data => {
    // ...
  })
  .catch(response => {
    // ...
  });

Adapter options

import axiosAdapter from 'bivrost-axios-adapter';

const api = axiosAdapter({
  // default options for each request with created adapter
  options: {
    withCredentials: false,
    xsrfCookieName: 'XSRF-TOKEN',
  },
});

Available options:

  • transformRequest - allows changes to the request data before it is sent to the server
  • transformResponse - allows changes to the response data to be made before
  • headers - are custom headers to be sent
  • paramsSerializer - is an optional function in charge of serializing params
  • timeout - specifies the number of milliseconds before the request times out
  • withCredentials - indicates whether or not cross-site Access-Control requests
  • auth - indicates that HTTP Basic auth should be used, and supplies credentials
  • responseType - indicates the type of data that the server will respond with
  • xsrfCookieName - is the name of the cookie to use as a value for xsrf token
  • xsrfHeaderName - is the name of the http header that carries the xsrf token value

More details - https://www.npmjs.com/package/axios#request-api

Interceptors

The main difference between axios-adapter interceptors and axios interceptorsis - is that interceptors could be specified for each adpater separately.

import axiosAdapter from 'bivrost-axios-adapter';

const api = axiosAdapter({
  interceptors: {
    request: request => {
      // ...
    },

    response: response => {
      // ...
    },

    error: response => {
      // ...
    },
  },
});

Interceptor example:

import axiosAdapter from 'bivrost-axios-adapter';

const api = axiosAdapter({
  interceptors: {
    response: httpResponse => httpResponse.data,
    error: httpErrorResponse => Promise.reject(httpErrorResponse),
  },
});

Bivrost allows to organize a simple interface to asyncronous APIs.

Other adapters

Keywords

FAQs

Package last updated on 14 May 2018

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