6d489f7a89
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> |
||
---|---|---|
karma | ||
src | ||
test | ||
.eslintrc | ||
.gitignore | ||
.npmignore | ||
.travis.yml | ||
CHANGELOG.md | ||
LICENSE | ||
README.md | ||
index.js | ||
karma.conf.js | ||
package-lock.json | ||
package.json | ||
tsconfig.json | ||
tsconfig.test.json |
README.md
SimpleRestClients
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);
}
}