https://github.com/binary-blazer/blink-http
A tiny and standalone HTTP client based on XMLHttpRequest
https://github.com/binary-blazer/blink-http
Last synced: about 2 months ago
JSON representation
A tiny and standalone HTTP client based on XMLHttpRequest
- Host: GitHub
- URL: https://github.com/binary-blazer/blink-http
- Owner: binary-blazer
- License: bsd-3-clause
- Created: 2025-03-09T11:43:46.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2025-03-09T12:56:11.000Z (2 months ago)
- Last Synced: 2025-03-09T12:56:35.053Z (2 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/blink-http
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Blink HTTP
A fast, elegant and standalone HTTP client.
[](https://www.npmjs.com/package/blink-http)
[](https://www.npmjs.com/package/blink-http)
[](https://github.com/binary-blazer/blink-http/actions/workflows/ci.yml)## Installation
You can install the package using npm, pnpm, yarn or bun.
```sh
npm install blink-http
# or
pnpm add blink-http
# or
yarn add blink-http
# or
bun install blink-http
```## Usage
### Basic Usage
#### with BaseURL:
```javascript
import { BlinkClient } from 'blink-http';const blink = new BlinkClient({
baseURL: 'https://jsonplaceholder.typicode.com', // is optional
timeout: 10000, // is optional
userAgent: 'custom-user-agent' // is optional
});const response = await blink.get('/posts/1');
console.log(await response.json()); // return response as JSON
```#### without BaseURL:
```javascript
import { BlinkClient } from 'blink-http';const blink = new BlinkClient({
timeout: 10000, // is optional
userAgent: 'custom-user-agent' // is optional
});const response = await blink.get('https://jsonplaceholder.typicode.com/posts/1');
console.log(await response.json()); // return response as JSON
```## Methods
- **`get`**
```typescript
get(url: string, options?: Omit, queryParams?: Record, onProgress?: (event: ProgressEvent) => void): Promise
```- **`post`**
```typescript
post(url: string, body: any, options?: Omit, queryParams?: Record, onProgress?: (event: ProgressEvent) => void): Promise
```- **`put`**
```typescript
put(url: string, body: any, options?: Omit, queryParams?: Record, onProgress?: (event: ProgressEvent) => void): Promise
```- **`delete`**
```typescript
delete(url: string, options?: Omit, queryParams?: Record, onProgress?: (event: ProgressEvent) => void): Promise
```- **`patch`**
```typescript
patch(url: string, body: any, options?: Omit, queryParams?: Record, onProgress?: (event: ProgressEvent) => void): Promise
```- **`head`**
```typescript
head(url: string, options?: Omit, queryParams?: Record, onProgress?: (event: ProgressEvent) => void): Promise
```- **`options`**
```typescript
options(url: string, options?: Omit, queryParams?: Record, onProgress?: (event: ProgressEvent) => void): Promise
```- **`trace`**
```typescript
trace(url: string, options?: Omit, queryParams?: Record, onProgress?: (event: ProgressEvent) => void): Promise
```## Examples
### GET Request
```javascript
const response = await blink.get('https://jsonplaceholder.typicode.com/posts/1');
console.log(response.json());
```### POST Request
```javascript
const response = await blink.post('https://jsonplaceholder.typicode.com/posts', { title: 'foo', body: 'bar', userId: 1 });
console.log(response.json());
```## Contributing
Please read the [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests.
## License
This project is licensed under the BSD-3-Clause License - see the [LICENSE](LICENSE) file for details.