šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

@postnord/http-service

Package Overview
Dependencies
Maintainers
33
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@postnord/http-service

A wrapper around `got` that gives a higher-level interface with generics

0.1.13
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
33
Weekly downloads
Ā 
Created
Source

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


FAQs

Package last updated on 30 Aug 2022

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