A simple set of wrappers for RESTful calls
Перейти к файлу
dependabot[bot] 6d489f7a89
Bump socket.io-parser from 4.0.4 to 4.0.5 (#81)
Bumps [socket.io-parser](https://github.com/socketio/socket.io-parser) from 4.0.4 to 4.0.5.
- [Release notes](https://github.com/socketio/socket.io-parser/releases)
- [Changelog](https://github.com/socketio/socket.io-parser/blob/main/CHANGELOG.md)
- [Commits](https://github.com/socketio/socket.io-parser/compare/4.0.4...4.0.5)

---
updated-dependencies:
- dependency-name: socket.io-parser
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-09 19:28:58 -08:00
karma Setup tests. Add basic GenericRestClient tests 2018-04-15 14:01:34 +03:00
src Removed SyncTasks from the project. Massively alterered tests to handle the new async behavior (#62) 2020-02-20 15:37:26 -07:00
test Removed SyncTasks from the project. Massively alterered tests to handle the new async behavior (#62) 2020-02-20 15:37:26 -07:00
.eslintrc 0.2.12: Publishing recent PR and updating all package versions, which pulled in a bunch of eslint changes that needed tweaking 2019-12-10 00:42:09 +01: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
.travis.yml Migrate to ESLint from TSLint 2019-05-20 14:30:52 +03:00
CHANGELOG.md Make blockRequestUntil work with MaxSimultaneousRequests and handle e… (#35) 2018-08-31 13:35:02 -07:00
LICENSE Add tests 2018-05-14 11:46:15 +03:00
README.md Removed SyncTasks from the project. Massively alterered tests to handle the new async behavior (#62) 2020-02-20 15:37:26 -07: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-lock.json Bump socket.io-parser from 4.0.4 to 4.0.5 (#81) 2022-11-09 19:28:58 -08:00
package.json Bump karma from 6.3.14 to 6.3.16 (#79) 2022-03-02 08:42:33 -07:00
tsconfig.json Removed SyncTasks from the project. Massively alterered tests to handle the new async behavior (#62) 2020-02-20 15:37:26 -07:00
tsconfig.test.json Setup tests. Add basic GenericRestClient tests 2018-04-15 14:01:34 +03:00

README.md

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);
    }
}