1.0.3 • Published 8 years ago

api-map v1.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

API Map

By: Robby Emmert

  • Define your API endpoints once, then call them with a one-liner from anywhere.
  • Implement global API settings such as headers and base url.
  • Switch API clients with one line of code.

Quick Start

  1. Install ApiMap to your project with npm install --save api-map

  2. Set up your global API settings, where resolver is a function that returns a promise, given a url, method, data, and network settings (read more about resolvers here or see a list of pre-build resolvers available on NPM here).

import { Api } from 'api-map';
import resolver from './custom-resolver';
// OR
import resolver from 'api-map-fetch-resolver' // or a pre-built resolver of your choice

var api = new Api({
    baseUrl: '/api',
    defaultHeaders: {
        contentType: 'application/json'
    }
}, resolver);
  1. Define your endpoints
var postList = api.map({
    url: '/posts',
    method: 'GET'
});

-or-

var singlePost = api.map({
    url: params => `/posts/${params.id}`
    // Method is 'GET' by default on all endpoint definitions.
});
  1. Query the api in DRY fashion:
postList.request()
    .then(res => console.log('result', res));

-or-

singlePost.request({ id: 123 })
    .then(res => console.log('result', res));
1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago