bivrost-localstorage-adapter

3.2.2 • Public • Published

Bivrost localStorage adapter

Bivrost adapter. Allows to work with localStorage as with REST backend

yarn add bivrost-local-storage-adapter

Usage

With Bivrost:

import DataSource from 'bivrost/data/source';
import bivrostApi from 'bivrost/http/api';
import localStorageAdapter from 'bivrost-local-storage-adapter';

const api = bivrostApi({
  adapter: localStorageAdapter({
    namespace: 'my-application',
  }),
});

class UsersDataSource extends DataSource {
  steps = ['api'];

  api = {
    loadAll: api('GET /users'),
    create: api('POST /users'),
  };

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

  createUser(user) {
    return this.invoke('create', user);
  }
}

Direct calls:

import localStorageAdapter from 'bivrost-local-storage-adapter';

const localStorageAdapter = localStorageAdapter({
  namespace: 'my-application',
});

localStorageAdapter('/users/1', {
  method: 'POST',
  body: {
    name: 'John Doe',
  },
}).then(() => console.log('saved to localStorage'));

localStorageAdapter('/users/1', {
  method: 'GET',
}).then(user => {
  expect(user).toEqual({
    name: 'John Doe',
  });
});

Bivrost allows to organize a simple interface to asyncronous APIs.

Other adapters

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i bivrost-localstorage-adapter

      Weekly Downloads

      10

      Version

      3.2.2

      License

      ISC

      Unpacked Size

      4.6 kB

      Total Files

      5

      Last publish

      Collaborators

      • tuchk4