# thip

> Ultra-Thin, Dependency-Free, Promise-Based HTTP request client.

Latest version **0.2.0** (published 2017-03-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install thip
pnpm add thip
yarn add thip
bun add thip
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2017-03-16 |
| First published | 2017-03-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 6 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | hoto17296 |
| Maintainers | hoto17296 |
| Keywords | http |

## Links

- npm: https://www.npmjs.com/package/thip
- Repository: https://github.com/hoto17296/thip
- Homepage: https://github.com/hoto17296/thip#readme
- Issues: https://github.com/hoto17296/thip/issues
- npm.io page: https://npm.io/package/thip

## Recent versions

- 0.2.0 (latest) — 2017-03-16
- 0.1.1 — 2017-03-15
- 0.1.0 — 2017-03-15

## README

# thip
[![Build Status](https://travis-ci.org/hoto17296/thip.svg)](https://travis-ci.org/hoto17296/thip)

Ultra-Thin, Dependency-Free, Promise-Based HTTP request client.

## Features
- Ultra thin, and lightweight
- Dependency free
- Promise based
- Only supports Node.js (>= 6), not supports browser
- Supports HTTPS
- Follows redirect by default

## Install
``` sh
npm install thip
```

## Usage
### thip(options[, data])
- `options` \<object\>|\<string\> - Any options not included below will be passed to [http.request(options)][http.request].
  - `url` \<string\> - If you specified this option, parse the url and merged to other options.
  - `followRedirect` \<boolean\> - Follow HTTP 3xx responses as redirects. Defaults to `true`.
  - `maxRedirects` \<number\> - The maximum number of redirects to follow. Defaults to `10`.
- data \<string\>|\<buffer\> - This will be passed to [request.write(chunk)][request.write].

[http.request]: https://nodejs.org/api/http.html#http_http_request_options_callback
[request.write]: https://nodejs.org/api/http.html#http_request_write_chunk_encoding_callback

This function returns `Promise` object which resolves response object.
The response object is an instance of [http.IncomingMessage][http.IncomingMessage], but contains `body` property.

[http.IncomingMessage]: https://nodejs.org/api/http.html#http_class_http_incomingmessage

``` js
const thip = require('thip');

thip('http://example.com/').then((res) => {
  console.log(res.body);
});
```

``` js
const thip = require('thip');
const querystring = require('querystring');

const data = querystring.stringify({
  'msg': 'Hello World!',
});

const options = {
  method: 'POST',
  url: 'http://example.com/message',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Content-Length': Buffer.byteLength(data),
  },
};

thip(options, data).then((res) => {
  console.log('Post successful!');
});
```

### thip.get(options[, data])
- `options.method` assigns `"GET"` by default.
- If `data` is \<object\>, the data is encoded as URL query.

``` js
thip.get('http://example.com/', { foo: 'bar' });
```

This is same as below.

``` js
thip('http://example.com/?foo=bar');
```

### thip.post(options[, data])
- `options.method` assigns `"POST"` by default.
- If `data` is \<object\>, the data is encoded as `x-www-form-urlencoded`.

``` js
const thip = require('thip');

thip.post('http://example.com/', { foo: 'bar' });
```

This is same as below.

``` js
const thip = require('thip');
const querystring = require('querystring');

const data = querystring.stringify({
  'foo': 'bar',
});

const options = {
  method: 'POST',
  url: 'http://example.com/',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Content-Length': Buffer.byteLength(data),
  },
};

thip(options, data);
```

---
_Source: https://npm.io/package/thip · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
