1.0.0 • Published 4 years ago

simplerestclients v1.0.0

Weekly downloads
4,655
License
MIT
Repository
github
Last release
4 years ago

SimpleRestClients

GitHub license npm version Build Status npm downloads npm bundle size (minified) npm bundle size (minified + gzip)

A simple set of wrappers for RESTful calls.

Installation

npm install --save simplerestclients

SimpleRestClients consists of two modules:

SimpleWebRequest

Wraps a single web request. Takes an options structure with overrides for priorization, delays, retry logic, error handling, etc. Has an abort() method to cancel the request early (will result in a rejected promise from the start() method).

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, Headers } from 'simplerestclients';

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): Headers {
        return { ...super._getHeaders(options), 'X-AppId': this._appId };
    }

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

    getUserById(id: string): Promise<User> {
        return this.performApiGet<User>(`user/${ id }`);
    }

    setUser(user: User): Promise<void> {
        return this.performApiPut<void>(`user/${ user.id }`, user);
    }
}
1.0.0

4 years ago

0.2.12

4 years ago

0.2.11

5 years ago

0.2.10

5 years ago

0.2.9

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago