A simple set of wrappers for RESTful calls
Перейти к файлу
Alexander T 759603a71e Fix CI build 2018-05-18 17:00:23 +03:00
karma Setup tests. Add basic GenericRestClient tests 2018-04-15 14:01:34 +03:00
src Fix CI build 2018-05-18 17:00:23 +03:00
test Add tests 2018-05-14 11:46:15 +03:00
.gitignore Misc cleanup 2016-11-02 15:57:33 -07:00
.npmignore Initial commit: Extracting out GenericRestClient, SimpleWebRequest, and ExponentialTime into a new SimpleRestClients reusable NPM module. 2016-11-02 15:52:44 -07:00
.npmrc Cleaned up SRC for strict null checks, newer Typescript/Tslint, and other compile flags. 2017-10-25 16:13:30 -07:00
.travis.yml Fix CI build 2018-05-18 17:00:23 +03:00
LICENSE Add tests 2018-05-14 11:46:15 +03:00
README.md Update README 2018-05-14 11:45:25 +03:00
index.js Misc cleanup 2016-11-02 15:57:33 -07:00
karma.conf.js Setup tests. Add basic GenericRestClient tests 2018-04-15 14:01:34 +03:00
package.json Fix CI build 2018-05-18 17:00:23 +03:00
tsconfig.json Merge branch 'master' into feature/tests 2018-05-07 17:00:16 +03:00
tsconfig.test.json Setup tests. Add basic GenericRestClient tests 2018-04-15 14:01:34 +03:00
tslint.json Feature/add default template parameters to web response (#24) 2018-04-24 18:43:31 -07:00

README.md

SimpleRestClients

GitHub license npm version npm downloads Build Status David David

A simple set of wrappers for RESTful calls. Consists of two modules:

SimpleWebRequest

Wraps a single web request. Has lots of overrides for priorization, delays, retry logic, error handling, etc.

GenericRestClient

Wraps SimpleWebRequest for usage across a single RESTful service. In our codebase, we have several specific RESTful service interaction classes that each implement GenericRestClient so that all of the requests get the same error handling, authentication, header-setting, etc.

GenericRestClient Sample Usage

import { GenericRestClient, ApiCallOptions }  from 'simplerestclients';
import SyncTasks = require('synctasks');

interface User {
    id: string;
    firstName: string;
    lastName: string;
}

class MyRestClient extends GenericRestClient {
    constructor(private _appId: string) {
        super('https://myhost.com/api/v1/');
    }

    // Override _getHeaders to append a custom header with the app ID.
    protected _getHeaders(options: ApiCallOptions): { [key: string]: string } {
        let headers = super._getHeaders(options);
        headers['X-AppId'] = this._appId;
        return headers;
    }

    // Define public methods that expose the APIs provided through
    // the REST service.
    getAllUsers(): SyncTasks.Promise<User[]> {
        return this.performApiGet<User[]>('users');
    }

    getUserById(id: string): SyncTasks.Promise<User> {
        return this.performApiGet<User>('user/' + id);
    }

    setUser(user: User): SyncTasks.Promise<void> {
        return this.performApiPut<void>('user/' + user.id, user);
    }
}