Skip to content

Latest commit

 

History

History

http-client

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Building block for Fetch API

This is a small, zero dependencies building block for creating HTTP clients based on native fetch api. It allows you to compose your fetch function easily.

Installation

npm install @zemd/http-client
pnpm add @zemd/http-client

Usage

import { compose, method, json } from "@zemd/http-client";

const myfetch = compose([method("POST"), json()], fetch);
// ^ myfetch is a `fetch` function with configured http method and Content-Type
const resp = await myfetch("https://example.com");
// ^ calling `myfetch` is the same as calling `fetch` with the same arguments

As you can see the configuration and usage are very simple and straightforward.

Some real-world examples you can find in ../apis/ folder.

A simple example you can also find here src/example.ts

License

@zemd/http-client released under the Apache 2.0 license

Donate