1.4.1 • Published 4 years ago
tra-typed-fetch v1.4.1
tra-typed-fetch
Table of Contents
About
A package that implements common http requests using fetch, allowing for typed responses with TypeScript.
Installing
npm install tra-typed-fetch
yarn add tra-typed-fetch
Usage
import { createHttpClient, get } from '@tra/typed-fetch';
interface Product {
name: string;
id: number;
}
type Products = Product[];
const response = await get<Products>({ url: '/products' });
// Where data will be the typed value bound to the function in the Response
const { data, headers, status } = response;
/*
Optional exported method to preset headers and baseUrl on each request
Note: currently only supports 1 http client. Existing calls to this function will return cached http client if exists.
*/
interface IRequestConfiguration {
baseUrl?: string;
defaultHeaders?: Request['headers'];
}
const { baseConfiguration, get, destroy, patch, post, put } = createHttpClient({
baseUrl: 'localhost:3000/api/v1/',
defaultHeaders: new Headers({ 'content-type': 'application/json' }),
});
1.4.1
4 years ago
1.4.0
4 years ago
1.3.8
4 years ago
1.3.7
4 years ago
1.3.6
4 years ago
1.3.5
4 years ago
1.3.4
4 years ago
1.3.3
4 years ago
1.3.2
4 years ago
1.3.1
4 years ago
1.3.0
4 years ago
1.2.8
4 years ago
1.2.9
4 years ago
1.2.7
4 years ago
1.2.6
4 years ago
1.2.5
4 years ago
1.2.4
4 years ago
1.2.3
4 years ago
1.2.2
4 years ago
1.2.1
4 years ago
1.2.0
4 years ago
1.1.9
4 years ago
1.1.8
4 years ago
1.1.7
4 years ago
1.1.6
4 years ago
1.1.5
4 years ago
1.1.4
4 years ago
1.1.3
4 years ago
1.1.2
4 years ago
1.1.1
4 years ago
1.1.0
4 years ago
1.0.9
4 years ago
1.0.8
4 years ago
1.0.7
4 years ago
1.0.6
4 years ago
1.0.5
4 years ago
1.0.4
4 years ago
1.0.3
4 years ago
1.0.2
4 years ago
1.0.0
4 years ago