# thin-request

> Thin http(s) promise request

Latest version **1.0.2** (published 2016-05-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install thin-request
pnpm add thin-request
yarn add thin-request
bun add thin-request
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2016-05-16 |
| First published | 2016-05-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Bjarne Oeverli |
| Maintainers | bjarneo |
| Keywords | kiss, thin, request, http, promise, put, post, get, patch, delete |

## Links

- npm: https://www.npmjs.com/package/thin-request
- Repository: https://github.com/bjarneo/thin-request
- Issues: https://github.com/bjarneo/thin-request/issues
- npm.io page: https://npm.io/package/thin-request

## Dependencies (1)

- [extend](https://npm.io/package/extend.md) 3.0.0

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2016-05-16
- 1.0.1 — 2016-05-15
- 1.0.0 — 2016-05-15

## README

Thin request
======
![Travis](https://travis-ci.org/bjarneo/thin-request.svg?branch=master)

Thin http(s) request promise wrapper.  

Installation
------
```bash
$ npm i --save thin-request
```

Usage
------
### GET
```js
request('https://www.endpoint.com', {
    path: '/user/1337',
    json: true // Sets application header to json. Also json parses the result.
})
.then(data => {
    // do whatever with the json result.
})
.catch(err => {
    throw new Error(err);
});
```

### POST
```js
request('https://www.endpoint.com', {
    path: '/user',
    method: 'POST',
    body: {
        data: 'posting'
    }
})
.then(data => {
    // do whatever with the result
})
.catch(err => {
    throw new Error(err);
});
```

### PUT
```js
request('https://www.endpoint.com', {
    path: '/user',
    method: 'PUT',
    body: {
        whatever: 'update/replace'
    }
})
.then(data => {
    // do whatever with the result
})
.catch(err => {
    throw new Error(err);
});
```

### DELETE
```js
request('https://www.endpoint.com', {
    path: '/user/1337'
})
.then(data => {
    // do whatever with the result
})
.catch(err => {
    throw new Error(err);
});
```

Options
------
This module takes care of these behind the scenes. You can easily override by defining
the ones you want in the input options.
```js
// parses the endpoint you provide
const url = require('url').parse(endpoint);

const opts = {
    hostname: url.hostname || params.hostname,
    port: url.port || params.port,
    path: url.path || params.path,
    protocol: url.protocol || params.protocol,
    json: false || params.json, // Take a look at GET example.
    method: params.method || 'GET',
    family: params.family || null,
    localAddress: params.localAddress || null,
    auth: params.auth || null,
    agent: params.agent || null,
    createConnection: params.createConnection || null
};
```
[Read more about options](https://nodejs.org/api/http.html#http_http_request_options_callback)

Tests
------
```bash
$ npm test
```

Contribution
------
Contributions are appreciated.

License
------
MIT-licensed. See LICENSE.

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