Easy and flexible HTTP client for the browser.
- ๐ Based on web standards (Fetch, URL, SearchParams, etc).
- ๐ค Modern browsers only.
- โก No dependencies.
- ๐ Written in TypeScript with exported types.
- ๐ฒ Conventional API, if you're familiar with Axios and the like.
- โฐ๏ธ Robust composability with extended instances and hooks.
- โ๏ธ Unique features like interpolation, customizable encoding and request merging (see below).
This is an over engineered example to showcase some of the features.
const httpbin = goget.extend({
url: "{schema}://httpbin.{tld}",
params: {
tld: "org",
},
reqHooks: [
async (req) => {
req.headers["x-api-key"] = "123";
return req;
},
],
});
const anything = httpbin.extend({
url: "/anything",
params: {
schema: "https",
},
});
const resp = await anything.post("test", {
params: {
one: 1,
},
data: {
message: "Hello!",
},
});
The above request will look like this:
HTTP
POST /anything/test?one=1
Host: https://httpbin.org
Content-type: application/json
x-api-key: 123
{"message":"Hello!"}
...
...
...
See ...
MIT ยฉ 2021 Arthur Corenzan