@postnord/http-service
TypeScript icon, indicating that this package has built-in type declarations

0.1.13 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @postnord/http-service

Weekly Downloads

3,426

Version

0.1.13

License

ISC

Unpacked Size

11.6 kB

Total Files

8

Last publish

Collaborators

  • cielomuyot.postnord
  • pn_rroble
  • damiant-postnord
  • erikedling
  • adamkillander
  • sculaste
  • bernhardhettman-pn
  • ashwin_postnord
  • fbopdin
  • elrmndo_pn
  • aliaksei.stryi-postnord
  • sang-canencia-npm-pn
  • pn-ost-base
  • retail-team-npm
  • eriklind-pn
  • postnord.aldee_mativo
  • raymund.galapate
  • romeo.obane
  • elias_sidenbladh
  • ncppublicservice
  • oaipostnord
  • pn-jroma
  • pn-foundation-deployer
  • pn-chester
  • pn-akilumanga
  • sabbir-rahman-sakib
  • jkaske-pn
  • pnrutbergphilip
  • pnorbert
  • kheycee.matarlo
  • johankarlsson-pn
  • sesam-publisher
  • vanessa.faith.abordo.postnord
  • avsceriola-pn
  • junlue-pn
  • pnncp-aftersales
  • mipe-pn
  • vbacalso
  • jonas_elfstrom
  • pn-webteam
  • postnord.npm
  • vbrigoli
  • jvalmores
  • vijilgirish
  • frqu300
  • access-login-publisher
  • joakim.hedlund.postnord
  • pn-fipe
  • pn-aronsson
  • m.usman
  • mahadiapn
  • ambots13