sodon-http
0.0.7 • Public • Published Simplifying fetch requests for less codes to type
Get request example below:
import {sodon_get} from "sodon-http/API";
const myFunction = async () => {
try {
const response = await sodon_get("https://jsonplaceholder.typicode.com/todos");
if (response.success) {
console.log("SUCCESS!", response.payload)
} else {
console.warn("WARNING!", response.message, response.status);
}
} catch (e) {
console.error(e);
}
}
import {postJson} from "sodon-http/API"
const myFunction = async () => {
try {
const form = {
title: "Foo",
body: "bar",
userId: 2,
}
const response = await sodon_postJson('https://jsonplaceholder.typicode.com/posts', form);
if (response.success) {
console.log("SUCCESS", response.payload);
} else {
console.warn("RESPONSE", response);
}
} catch (e) {
console.error(e)
}
}
Post multipart form data as below
import {postJson} from "sodon-http/API"
const myFunction = async () => {
try {
const form = new FormData();
form.append("title", "foo");
form.append("name", "bar");
form.append("userId", "2");
const response = await sodon_postMultiPartForm('https://jsonplaceholder.typicode.com/posts', form);
if (response.success) {
console.log("SUCCESS", response.payload);
} else {
console.warn("RESPONSE", response);
}
} catch (e) {
console.error(e)
}
}
Package Sidebar
Install
Weekly Downloads