Compare commits

..

No commits in common. "a95d003ed54469afb625556decb1e339b5741700" and "95a12a82850a16c50ea239c7056c8f1807bc7564" have entirely different histories.

1 changed files with 5 additions and 20 deletions

View File

@ -48,29 +48,14 @@ In order to keep this library lightweight, performant, and keep the code easy to
read, the streaming behavior is **_slightly different_** from that of
`request.js`.
```diff
-var request = require('request');
+var request = require('@root/request');
-var stream = request({ url, headers });
+var stream = await request({ url, headers });
let attachment = await new MailgunAPI.Attachment({
data: stream
})
```
Example:
```js
var request = require('@root/request');
var resp = await request({
url: 'http://www.google.com',
stream: true // true | 'filename.ext' | stream.Writable
stream: true
});
// 'resp' itself is a ReadableStream
resp.on('data', function () {
// got some data
});
@ -79,8 +64,8 @@ resp.on('end', function () {
// the data has ended
});
// 'resp.stream' is a Promise that is resolved when the read stream is destroyed
await resp.stream; // returns `undefined`
// resp.stream is a Promise that is resolved when the read stream is destroyed
await resp.stream;
console.log('Done');
```
@ -141,12 +126,12 @@ request.post('http://service.com/upload').form({key:'value'})
#### multipart/form-data (Multipart Form Uploads)
For `multipart/form-data` we use the [form-data](https://github.com/form-data/form-data/tree/v2.5.1) library by [@felixge](https://github.com/felixge). For the most cases, you can pass your upload form data via the `formData` option.
For `multipart/form-data` we use the [form-data](https://github.com/form-data/form-data) library by [@felixge](https://github.com/felixge). For the most cases, you can pass your upload form data via the `formData` option.
To use `form-data`, you must install it separately:
```bash
npm install --save form-data@2.x
npm install --save form-data@2
```
```js