Simple HTTP Client built with zero dependency.
npm install hanif-tiny-http --only=prod
yarn add hanif-tiny-http --production
ES
import { TinyHttpClient } from "hanif-tiny-http";
const client = new TinyHttpClient({
baseURL: "https://hastebin.com"
});
interface HastebinOut {
key: string;
}
client.post("documents", "hello-world").then((response) => {
response.getJSON<HastebinOut>().then((json) => {
console.log(json.key);
});
});
CJS
const { TinyHttpClient } = require("hanif-tiny-http");
const client = new TinyHttpClient({
baseURL: "https://hastebin.com"
});
client.post("documents", "hello-world").then((response) => {
response.getJSON().then((json) => {
console.log(json.key);
});
});
Do you want to download a video or something with streaming mode? Well, that's probably here.
Simply enter 'stream' in the request option, fill it with a boolean value.
Example:
client.get('https://somesite.com', { stream: true }).then((response) => {
response.stream; // use it.
});
Also, if you want get download progress that's possible here.
onDownload
won't work without stream mode.
client.get('https://somesite.com', { stream: true }).then((response) => {
response.onDownload((totalBytes, downloadedBytes) => {
// stuff..
});
});
What's difference?
If the stream option is enabled, you'll receive a response class instantly without having the response content load perfectly.
If the stream option is disabled, you'll need to wait until the response content loads correctly.
You are welcome to contribute this package.
if you want
This package is intended for personal use.
Generated using TypeDoc