Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cancerberosgx/hyperquest-promise
hyperquest returning promises - flexible request library supporting node.js and browser with the same API based on Promises
https://github.com/cancerberosgx/hyperquest-promise
Last synced: about 2 months ago
JSON representation
hyperquest returning promises - flexible request library supporting node.js and browser with the same API based on Promises
- Host: GitHub
- URL: https://github.com/cancerberosgx/hyperquest-promise
- Owner: cancerberoSgx
- License: mit
- Created: 2018-05-10T08:23:58.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T02:53:41.000Z (about 2 years ago)
- Last Synced: 2024-11-09T18:03:39.793Z (2 months ago)
- Language: TypeScript
- Homepage:
- Size: 49.8 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/cancerberoSgx/hyperquest-promise.png?branch=master)](https://travis-ci.org/cancerberoSgx/hyperquest-promise)
[![Dependencies](https://david-dm.org/cancerberosgx/hyperquest-promise.svg)](https://david-dm.org/cancerberosgx/hyperquest-promise)# Hyperquest returning Promises
[hyperquest](https://github.com/substack/hyperquest) returning promises
Same API, same code, both in browser and node.js.
For those not familiar, this is library for making requests that will work both in node.js and browser thanks to browserify or similar bundler.
## Install
```npm install --save hyperquest-promise ```
## Usage
Use async/await for shorter syntax. Resolves with a Request object and request.data is a Buffer. By default encodes text as binary.
```ts
import { get } from 'hyperquest-promise'(async () => {
const {buffer} = await get('https://foo.com/f/bar.jpg')
writeFileSync('bar.jpg', buffer)
})();export async function getSpotifyProfile() {
const response = await get('https://api.spotify.com/v1/me/playlists',
{headers: {Authorization: `Bearer ${THE_TOKEN}`}})
return (!response || !response.data) ? null || JSON.parse(response.data.toString())
}
```## API documentation
For API documentation , please go to [hyperquest](https://github.com/substack/hyperquest) or [request](https://github.com/request/request).
The API is the same as hyperquest with the only difference that methods will return a `Promise`.
### Options signature
* `url?: string`:
* `scheme?: string`:
* `method?: string`:
* `host?: string`:
* `port?: string`:
* `encoding?: string`:
* `path?: string`:
* `agent?: string | false`:
* `headers?: Headers`:
* `withCredentials?: any`:
* `localAddress?: any`:
* `pfx?: any`:
* `key?: any`:
* `cert?: any`:
* `ca?: any`:
* `ciphers?: any`:
* `rejectUnauthorized?: any`:
* `secureProtocol?: any`: