@postnord/http-service
v0.1.13
Published
A wrapper around `got` that gives a higher-level interface with generics
Downloads
15,161
Maintainers
Keywords
Readme
Introduction
A wrapper around got
that gives a higher-level interface with generics.
Features
- Pleasant interface where you pass in objects to all methods, making it more readable.
- Generics to define the expected response body.
- Default options set upfront that could be overridden on individual calls, DRYing your code while making it flexible when needed.
Quick start
import HttpService from '@postnord/http-service'
/**
* You could optionally instantiate the service with default config.
* Each config can be overridden on individual calls to methods.
**/
const service = new HttpService({
parseJson: true,
retry: 3
})
/**
* You could define what body you're expecting to get
**/
interface ExpectedBody {
completed: boolean
id: number
title: string
userId: number
}
const res = await service.get<ExpectedBody>({ url: `https://jsonplaceholder.typicode.com/todos/1` })
// res.responseBody will be typed as ExpectedBody