sodon-http
v0.0.8
Published
"Sodon-HTTP" is a lightweight and flexible HTTP client for Node.js, designed to simplify and streamline HTTP requests. It provides an intuitive interface for making HTTP requests, handling responses, and managing headers effortlessly. With support for var
Downloads
17
Readme
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);
}
}
Post JSON data as below
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)
}
}