1.1.3 • Published 1 year ago

@jkob/fetchy v1.1.3

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Fetchy

import { Fetchy } from "@jkob/browser";

const fetchy = new Fetchy("https://website.com/api");

// regular GET request
// calls "https://website.com/api/users", returns something like { status: 200, data: [] }
const response = await fetchy.get({ path: "/users" });

// with params
// calls "https://website.com/api/users?id=14", returns something like { status: 200, data: [] }
const response = await fetchy.get({ path: "/users", params: { id: 14 } });

// POST request with data
const response = await fetchy.post({ path: "/user", data: { name: "John" } });

// additional headers (default ones has json support already!)
const response = await fetchy.post({
	path: "/user",
	data: { name: "John" },
	headers: { Authorization: "Bearer: xx...." },
});

// cancel request
const controller = new AbortController();
fetchy
	.get({
		path: "/user",
		controller,
	})
	.then((response) => {
		console.log("This will never run");
	});
controller.abort();
1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago