1.4.0 • Published 6 months ago

@genee/rest v1.4.0

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

@genee/rest

Usage

import REST from '@genee/rest';

type UserData = {
    id: number;
    name: string;
};

class UserService extends REST {
    private token: string;

    construct() {
        super('https://host/base/url/api');
    }

    // will be called only once before the very first request
    protected async init() {
        // you have to use rawRequest
        this.token = await this.rawRequest(this.url('v1/token'));
    }

    // pass inited token to headers in each request
    protected get additionalHeaders() {
        return {
            Authorization: `Bearer ${this.token}`;
        }
    }

    // or pass inited token to queries in each request
    protected get additionalQueries() {
        return {
            token: this.token;
        }
    }
}

(async () => {
    const gateway = new REST('https://host/base/url/api');
    const user = await gateway.post<UserData>('v1/user', {
        name: 'Doe John'
    });
})();
1.4.0

6 months ago

1.3.0

9 months ago

1.2.0

2 years ago

1.2.2

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.2

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago