Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

authenticated-json-fetch-client

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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.

latest
Source
npmnpm
Version
1.0.7
Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 15 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts