bivrost
Bivrost allows to organize a simple interface to asynchronous APIs.
Last updated 2 years ago by tuchk4 .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install bivrost 
SYNC missed versions from official npm registry.

Bivrost

Bivrost allows to organize a simple interface to asynchronous APIs.

build status npm version

Fetch API Call

Easiet way to use fetch with interceptros and awesome api endpoint declaration. bivrost/packages/fetch-api-call

Bivrost

The main idea of Bivrost is grouping several API methods into data-sources.

Bivrost full documentation and recipes

Installation

yarn add bivrost

The gist

That’s it! Create api function for github api.

import api from 'bivrost/http/api'
import fetchAdapter from 'bivrost-fetch-adapter';

const githubApi = api({
  protocol: 'https:'
  host: 'api.github.com',
  adapter: fetchAdapter()
});

//define API method
const repositoryList = githubApi('GET /users/:user/repos'),

//call API method
repositoryList({ user: 'tuchk4' })
  .then(repositories => console.log(repositories));

Create data source that contain few github api methods (get repositories list and get repository info) and its invoke chain.

import DataSource from 'bivrost/data/source';
import githubApi from './github-api';
import tcomb from 'tcomb';

class GihtubRepositories extends DataSource {
  // define invoke method chain. Default chain is - ['api', 'process']
  static steps = ['api', 'immutable'];

  // "define "api" step
  static api = {
    repos: githubApi('GET /users/:user/repos'),
    repoInfo: githubApi('GET /repos/:user/:repository'),
  };

  // step function will be executed for each method
  static immutable = response => Immutable.fromJSON(response);

  // define data source public methods that invokes steps methods
  getRepositories(user) {
    return this.invoke('repos', {
      user,
    });
  }

  getRepositoryInfo(user, repository) {
    return this.invoke('repoInfo', {
      user,
      repository,
    });
  }
}

Extends GihtubRepositories and define username. Now all requests will be done for facebook's github group.

import GihtubRepositories from './github-repositories';

const FACEBOOK_GITHUB_ACCOUNT = 'facebook';

class FacebookRepositories extends GihtubRepositories {
  getRepositories() {
    return super.getRepositories(FACEBOOK_GITHUB_ACCOUNT);
  }

  getRepositoryInfo(repository) {
    return super.getRepositoryInfo(FACEBOOK_GITHUB_ACCOUNT, repository);
  }
}

Contributing

Project is open for new ideas and features:

  • new adapters
  • new api functions
  • data source features
  • feedback is very matter

Docs

Adapters

Current Tags

  • 3.2.6-alpha.4                                ...           canary (2 years ago)
  • 3.2.5                                ...           latest (2 years ago)

27 Versions

  • 3.2.6-alpha.4                                ...           2 years ago
  • 3.2.6-alpha.2                                ...           2 years ago
  • 3.2.6-alpha.1                                ...           2 years ago
  • 3.2.5                                ...           2 years ago
  • 3.2.2                                ...           2 years ago
  • 3.2.0                                ...           2 years ago
  • 3.1.2                                ...           2 years ago
  • 3.1.1                                ...           2 years ago
  • 3.1.0                                ...           3 years ago
  • 3.0.2                                ...           3 years ago
  • 3.0.1                                ...           3 years ago
  • 3.0.0                                ...           3 years ago
  • 2.3.1                                ...           3 years ago
  • 2.2.6                                ...           3 years ago
  • 2.2.5                                ...           3 years ago
  • 2.2.4                                ...           3 years ago
  • 2.2.3                                ...           4 years ago
  • 2.2.2                                ...           4 years ago
  • 2.2.1                                ...           4 years ago
  • 2.2.0                                ...           4 years ago
  • 2.1.1                                ...           4 years ago
  • 2.1.0                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 0.0.10                                ...           5 years ago
  • 0.0.7                                ...           5 years ago
  • 0.0.6-0                                ...           5 years ago
  • 0.0.5                                ...           5 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (1)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |