Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wikimedia/preq
Yet another promising node-request wrapper
https://github.com/wikimedia/preq
javascript nodejs preq promise request wrapper
Last synced: about 1 month ago
JSON representation
Yet another promising node-request wrapper
- Host: GitHub
- URL: https://github.com/wikimedia/preq
- Owner: wikimedia
- Created: 2014-09-24T18:52:02.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2020-01-13T17:46:19.000Z (almost 5 years ago)
- Last Synced: 2024-10-01T14:41:55.454Z (about 1 month ago)
- Topics: javascript, nodejs, preq, promise, request, wrapper
- Language: JavaScript
- Homepage:
- Size: 98.6 KB
- Stars: 4
- Watchers: 12
- Forks: 13
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# preq [![Build Status](https://travis-ci.org/wikimedia/preq.svg?branch=master)](https://travis-ci.org/wikimedia/preq)
Yet another promising [request](https://github.com/request/request) wrapper.
## Features
- ES6 `Promise`-based, using the excellent
[bluebird](https://github.com/petkaantonov/bluebird/blob/master/API.md) by
default
- Robustness: retry, timeout and connect timeout support
- Proper error handling: All errors (incl. HTTP responses with code >= 400)
throw exceptions, and can be caught with `Promise.catch()`. This ensures
that all errors are handled, and often cleans up the code by clearly
separating out error handling. The `HTTPError` instance has all the
properties of a normal response.## Installation
```
npm install preq
```## Usage
```javascript
var preq = require('preq');return preq.get({ // or preq.request({ method: 'get', .. })
uri: 'http://google.com/',
headers: {
'x-foo': 'bar'
},
query: {
q: 'foo'
},
// body for POSTs or PUTs, can be object (serialized to JSON), Buffer or String
})
.then(function(res) {
/**
* {
* status: 200,
* headers: {
* date: 'Sat, 21 Feb 2015 01:47:40 GMT' // , ...
* },
* body: '...