Skip to content
This repository was archived by the owner on May 15, 2022. It is now read-only.

hansputera/tiny-http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

c7f566c · May 15, 2022

History

33 Commits
Oct 26, 2021
Nov 4, 2021
May 15, 2022
May 15, 2022
Nov 4, 2021
May 15, 2022
Nov 4, 2021
May 15, 2022
May 15, 2022
Nov 4, 2021
May 15, 2022
Nov 4, 2021
Nov 16, 2021
May 15, 2022
Nov 4, 2021
Oct 5, 2021
May 15, 2022

Repository files navigation

My Tiny HTTP Client

Simple HTTP Client built with zero dependency.

Installation

npm install hanif-tiny-http --only=prod

yarn add hanif-tiny-http --production

Basic usage

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);
    });
});

Stream Usage

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.

Contribution

You are welcome to contribute this package. if you want

Note

This package is intended for personal use.