REST Client

Introduction

The EJS REST Client is a powerful facility for working with REST APIs. With built-in path prefixing, token management, advanced error handling, convenience methods, and a Promise-based architecture, making API requests has never been easier!

Leveraging the strengths of the EJS HTTP Client 'under-the-hood', it is also possible to dig into the details of requests and responses, whether or not the request was successful.

The RestClient Class

Synopsis

class RestClient {
    constructor(string basePath, string token);

    api(string method, string path, Object args, Object headers = {}) : Promise<Response>

    get(string path, Object args = {}) : Promise<Response>
    post(string path, Object args = {}) : Promise<Response>
    put(string path, Object args = {}) : Promise<Response>
    delete(string path, Object args = {}) : Promise<Response>

    encodeQuery(Object args = {}) : string
}

Examples

Instantiate RestClient

Request Methods

Simple Example

Exhaustive Example

Batching requests

Each of the request methods in RestClient return a Promise object. You can collect these Promise objects into an array, and use the native Promise.all() method to wait for all of them to resolve.

Last updated