Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hansputera/tiny-http
My Tiny HTTP Client with zero dependency.
https://github.com/hansputera/tiny-http
education http https javascript nodejs typescript
Last synced: 2 months ago
JSON representation
My Tiny HTTP Client with zero dependency.
- Host: GitHub
- URL: https://github.com/hansputera/tiny-http
- Owner: hansputera
- Archived: true
- Created: 2021-10-05T08:15:23.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-05-15T13:32:02.000Z (over 2 years ago)
- Last Synced: 2024-08-01T21:46:26.983Z (4 months ago)
- Topics: education, http, https, javascript, nodejs, typescript
- Language: TypeScript
- Homepage: https://hansputera.github.io/tiny-http/
- Size: 294 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-made-by-indonesian - Tiny HTTP Client - `Tiny HTTP Client with zero dependency.` *by [Hanif Dwy Putra S](https://github.com/hansputera)* (T)
- made-in-indonesia - Tiny HTTP Client - `Tiny HTTP Client with zero dependency.` *by [Hanif Dwy Putra S](https://github.com/hansputera)* (T)
README
# 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
```typescript
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().then((json) => {
console.log(json.key);
});
});
```CJS
```javascript
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:**
```ts
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.```ts
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.