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