modern-http

1.0.1 • Public • Published

Modern HTTP

A modern HTTP client, using fetch without all the boilerplate.

Modern HTTP is a tiny HTTP client. It uses Fetch, and returns Promises, but saves the boilerplate required by fetch:

  • Uses JSON by default
  • Uses real HTTP methods. No 'fetching a POST' (!?), just .post()
  • JavaScript objects will be automatically sent as JSON
  • Ready to use response.body - uses content types to decode
  • Ready to use response.headers. No iterators with hidden keys, .next() etc

Usage

import httpClient from './modern-http.js'

GET

let response = await httpClient.get('/api/v1/subscription/123456')

POST

let response = await httpClient.post('/api/v1/subscription', {
    email: serverVars.email,
    paymentSourceID: source.id,
    planID 
})

Goals, Aims, Status etc

This is a very early work in progress, made in a few hours one morning. The aim is to:

  • Encoding URL query strings from an Object
  • Support for plaintext etc responses

The aim is to be as small as possible, using browser technologies, but not wasting developer time for common workflows. Esentially similar to high-level mid 2010's HTTP clients like superagent, axios, etc. but built on top of modern tech, which has a few advantages (in built Promises, possible request cancellation in future).

Essentially to make a modern HTTP client that is better, not worse, than the things it replaces.

Readme

Keywords

Package Sidebar

Install

npm i modern-http

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

4.21 kB

Total Files

3

Last publish

Collaborators

  • mikemaccana