0.0.6 • Published 2 years ago
@mvdlei/web v0.0.6
Web package
Web package with pre-configured fetch for HTTP API requests.
Installation
npm install @mvdlei/webUsage
import { api } from "@mvdlei/web";
api.get("https://api.example.com/data").then((response) => console.log(response));With body
api("https://api.example.com/data", {
method: "POST",
body: { example: "example" },
}).then((data) => console.log(data));Can throw:
try {
const data = await api("https://api.example.com/data", {
method: "POST",
body: { example: "example" },
});
} catch (error) {
if (HttpError.is(error)) {
// handle http error
error.response;
}
}License
MIT