A simple set of wrappers for RESTful calls
Перейти к файлу
dependabot[bot] fda6f0c34f
Bump minimist and mkdirp
Bumps [minimist](https://github.com/minimistjs/minimist) and [mkdirp](https://github.com/isaacs/node-mkdirp). These dependencies needed to be updated together.

Updates `minimist` from 1.2.5 to 1.2.8
- [Release notes](https://github.com/minimistjs/minimist/releases)
- [Changelog](https://github.com/minimistjs/minimist/blob/main/CHANGELOG.md)
- [Commits](https://github.com/minimistjs/minimist/compare/v1.2.5...v1.2.8)

Updates `mkdirp` from 0.5.1 to 0.5.6
- [Release notes](https://github.com/isaacs/node-mkdirp/releases)
- [Changelog](https://github.com/isaacs/node-mkdirp/blob/main/CHANGELOG.md)
- [Commits](https://github.com/isaacs/node-mkdirp/compare/0.5.1...v0.5.6)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
- dependency-name: mkdirp
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-02 09:32:43 +00: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 minimist and mkdirp 2023-03-02 09:32:43 +00:00
package.json Bump json5, karma-webpack, ts-loader and webpack (#92) 2023-01-01 02:44:37 -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);
    }
}