JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 780
  • Score
    100M100P100Q121309F
  • License MIT

Simple API Client for JavaScript

Package Exports

  • @moqada/simple-api-client

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@moqada/simple-api-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

simple-api-client

NPM version Build Status Coverage Status Dependency Status DevDependency Status License

Simple API Client for JavaScript.

WIP

Installation

npm install --save @moqada/simple-api-client

Usage

import SimpleAPIClient from '@moqada/simple-api-client';

class APIClinet extends SimpleAPIClient {

  constructor({token, custom}: {token: string, custom: string}) {
    super();
    this.token = token;
    this.custom = custom;
  }

  getDefaultOptions(): Object {
    return {
      headers: {
        'Authorization': `Bearer ${this.token}`,
        'X-Custom-Header': `${this.custom}`
      }
    };
  }

  toResponse(error: ?Object, response: ?Object): Object {
    if (error) {
      return {error};
    }
    return {
      body: response.body
    };
  }

  getUsers(query): Promise<{body: Object}, {error: Object}> {
    return this.get('/users', {query});
  }
}
APIClinet.endpoint = 'http://api.example.com/v1'

const clinet = new APIClinet({token: 'xxxxxxxyyyyy', custom: 'foobar'});
client.getUsers({offset: 20, limit: 10}).then(({body}) => {
  console.log(body);
}).catch(({error}) => {
  console.error(error);
}):

Todo

  • Test