# @fatmatto/ptth

> Zero-dependencies, promise-based wrapper around node native http module.

Latest version **1.6.0** (published 2024-02-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @fatmatto/ptth
pnpm add @fatmatto/ptth
yarn add @fatmatto/ptth
bun add @fatmatto/ptth
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.6.0 |
| Published | 2024-02-04 |
| First published | 2019-01-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 10.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Mattia Alfieri |
| Maintainers | fatmatto |
| Keywords | http, simple, util, utility |

## Links

- npm: https://www.npmjs.com/package/@fatmatto/ptth
- Repository: https://gitlab.com/fatmatto/ptth
- Homepage: https://gitlab.com/fatmatto/ptth#readme
- Issues: https://gitlab.com/fatmatto/ptth/issues
- npm.io page: https://npm.io/package/@fatmatto/ptth

## Dependencies (1)

- [follow-redirects](https://npm.io/package/follow-redirects.md) ^1.7.0

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 1.6.0 (latest) — 2024-02-04
- 1.5.7 — 2021-05-10
- 1.5.6 — 2021-05-10
- 1.5.5 — 2020-12-08
- 1.5.4 — 2020-11-20
- 1.5.2 — 2019-08-06
- 1.5.1 — 2019-08-05
- 1.5.0 — 2019-07-25
- 1.4.3 — 2019-01-22
- 1.4.2 — 2019-01-21
- 1.4.0 — 2019-01-16
- 1.3.0 — 2019-01-16
- 1.2.0 — 2019-01-16
- 1.1.0 — 2019-01-16

## README

# PTTH

<p align="center"> Small, promise-based  wrapper around node native http module </p>

<hr/>
Hello!

<p> I wanted a simple promise layer on top of native http/https nodejs modules</p>

### List of features

* Promises
* Simplicity



### GET request example

```javascript


const http = require('ptth')

http({
  method: 'GET',
  uri: 'http://example.org',
  query: {
    boolean: true,
    number:1,
    string: "Ciao"
  },
  headers: {
    'x-request-id': '121121212'
  }
})
  .then((resp) => {
    console.log(`Status code is ${resp.statusCode}`)
    console.log('Headers:', resp.headers)
    console.log('Body:', resp.body)
  })
  .catch(console.error)
```

### POST request example
```javascript
  http({
  method: 'POST',
  uri: 'http://example.org',
  body: {
    boolean: true,
    number:1,
    string: "Ciao"
  },
  headers: {
    'x-request-id': '121121212'
  }
})
  .then((resp) => {
    console.log(`Status code is ${resp.statusCode}`)
    console.log('Headers:', resp.headers)
    console.log('Body:', resp.body)
  })
  .catch(console.error)
```
### Using Async/Await
```javascript

  let response = await http({
  method: 'POST',
  uri: 'http://example.org',
  body: {
    boolean: true,
    number:1,
    string: "Ciao"
  },
  headers: {
    'x-request-id': '121121212'
  }
})

console.log(`Status code is ${response.statusCode}`)
console.log('Headers:', response.headers)
console.log('Body:', response.body)
```

### Using a custom HTTP Agent
```javascript

const https = require('https')

  let response = await http({
    agent: new https.Agent({
      rejectUnauthorized: false
    }),
    method: 'GET',
    uri: 'https://somesitewithabadSSLcertificate.com'
  })
}

console.log(`Status code is ${response.statusCode}`)
console.log('Headers:', response.headers)
console.log('Body:', response.body)
```


### Params

| Name | Type | Description | Required | Default |
| ---- | ---- | ----------- | -------  | ------- |
| method  | String | HTTP Method | Yes    |    -    |
| uri     | String | HTTP Uri   | Yes    |    -    |
| headers | Object | HTTP headers | No    |    -    |
| query   | Object | HTTP query object that builds the querystring | No      |    -    |
| body    | Object | HTTP body | No       |    -    |
| pipeTo  | Stream | Writable stream | No     |    -    |
| json    |Boolean | If set to false the response is not parsed as json | No   |     true    |


### Interceptors

**Request interceptors**

```javascript
  http.interceptors.request.use(config => {
    config.headers.foo = 'bar'
    return config
  })
```

**Response interceptors**

```javascript
  http.interceptors.response.use(response => {
    // Do something with response
    return response
  })
```

### Download & Installation

```shell
$ npm i @fatmatto/ptth
```
### Contributing
Keep it simple. Keep it minimal. Don't put every single feature just because you can.

### Authors or Acknowledgments

* Mattia 'fat' Alfieri

### License

This project is licensed under the MIT License

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