0.0.4 • Published 3 years ago

vortex-ext-http v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Vortex Extensions HTTP Client

A simple library powered by Axios to take the boilerplate out of making HTTP API requests from Vortex extensions.

Usage

We strongly recommend using this library with TypeScript extensions and no support will be provided for JS extensions.

Since every extension's use case will be a little different, this library is designed around abstract classes that you can implement and tweak in your own extension. The main component is the HttpClient class. Implement a class that extends the HttpClient class to get start:

class ApiClient extends HttpClient {
    constructor() {
        super('MyAwesomeExtension/0.1.0'); // user agent
    }
}

Now you can implement your own API surface to match your extension's requirements using the getApiResponse<T> function in the base class:

class ApiClient extends HttpClient {
    // trimmed

    getModDetails = async (modId: string): Promise<IModDetails> | null => {
        var url =  `https://sickmods.com/api/mod/${modId}`;
        var mod = await this.getApiResponse<IModDetails>(url, (data) => data[0])
        return mod;
    }
}

The typings (and tsdoc) should make the usage reasonably self-explanatory, but some more documentation should be coming soon.

There is also a cached HTTP client that can be used in conjunction with the session state to work as a caching layer, but this is in early alpha and is likely unstable.

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago