Compare commits
2 Commits
95a12a8285
...
a95d003ed5
Author | SHA1 | Date |
---|---|---|
AJ ONeal | a95d003ed5 | |
AJ ONeal | 5149bc9dcb |
25
README.md
25
README.md
|
@ -48,14 +48,29 @@ 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
|
||||
stream: true // true | 'filename.ext' | stream.Writable
|
||||
});
|
||||
|
||||
// 'resp' itself is a ReadableStream
|
||||
resp.on('data', function () {
|
||||
// got some data
|
||||
});
|
||||
|
@ -64,8 +79,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;
|
||||
// 'resp.stream' is a Promise that is resolved when the read stream is destroyed
|
||||
await resp.stream; // returns `undefined`
|
||||
console.log('Done');
|
||||
```
|
||||
|
||||
|
@ -126,12 +141,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) 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/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.
|
||||
|
||||
To use `form-data`, you must install it separately:
|
||||
|
||||
```bash
|
||||
npm install --save form-data@2
|
||||
npm install --save form-data@2.x
|
||||
```
|
||||
|
||||
```js
|
||||
|
|
Loading…
Reference in New Issue