1.0.7 • Published 5 years ago

authenticated-json-fetch-client v1.0.7

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

authenticated-json-fetch-client

A TypeScript base class for building clients for fetch-based JSON APIs that are authenticated by a secret given in a param or header.

Installation

yarn add authenticated-json-fetch-client
# OR
npm install --save authenticated-json-fetch-client

Usage

import API from 'authenticated-json-fetch-client;

interface User {
    id: number;
    username: string;
}

export class MyAPI extends API {
    constructor(secret: string, host = 'http://localhost:8000') {
        const secretParamName = 'token';
        // To include the secret param as an HTTP header, set `secretParamName` to `"header:Some-Header"`
        // (or set it to `"header:"` which defaults to `"header:Authorization"`)
        super({host, secret, secretParamName});
    }

    getAllUsers(): Promise<User[]> {
        return this.GET<User[]>('/users');
    }
}

Copyright 2019 Duncan Smith

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago