https://github.com/tiaanduplessis/puny-req
📡 Lightweight promise based HTTP(S) request library
https://github.com/tiaanduplessis/puny-req
http https puny request
Last synced: 9 months ago
JSON representation
📡 Lightweight promise based HTTP(S) request library
- Host: GitHub
- URL: https://github.com/tiaanduplessis/puny-req
- Owner: tiaanduplessis
- License: mit
- Created: 2017-04-04T15:35:56.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-06-12T04:11:17.000Z (about 6 years ago)
- Last Synced: 2025-06-09T11:49:22.684Z (about 1 year ago)
- Topics: http, https, puny, request
- Language: JavaScript
- Homepage:
- Size: 216 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
📡 req
📡 Lightweight promise based HTTP(S) request library
Table of Contents
Table of Contents
## Install
[](https://greenkeeper.io/)
```sh
$ npm install --save puny-req
# OR
$ yarn add puny-req
```
## Usage
```js
const req = require('puny-req')
// GET request
req('https://jsonplaceholder.typicode.com/posts/1').then((res) => {
console.log(res.headers, res.body)
}).catch(console.log)
// POST request
req({
url: 'https://jsonplaceholder.typicode.com/posts',
json: {
title: 'Hi', body: 'Friend', userId: 1
}
}).then((res) => {
console.log(res.headers, res.body)
}).catch(console.log)
```
## API
Module exports a single function that returns a promise. It accepts a url string as argument for simple `GET` requests or an object with the following options:
```js
{
url: String, // (Required)
port: Int, // Port of request. Defaults to 80 or 443 depending on protocol
headers :Object, // Headers associated with request. If form or json property provided, correct headers will be added
method: String, // Method of request, Defaults to GET or POST if form or json property provided
auth: String, // Authorization in 'user:password' format
encoding: String // Encoding defaulted to UTF-8
form: Object || String, // form data to POST
json: Object // Object to POST,
}
```
The promise resolves with the response object. The body is parsed to a object if possible.
## Contribute
Contributions are welcome. Please open up an issue or create PR if you would like to help out.
Note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
## License
Licensed under the MIT License.