mirror of
				https://github.com/therootcompany/request.js.git
				synced 2024-11-16 17:28:58 +00:00 
			
		
		
		
	Compare commits
	
		
			No commits in common. "a95d003ed54469afb625556decb1e339b5741700" and "95a12a82850a16c50ea239c7056c8f1807bc7564" have entirely different histories.
		
	
	
		
			a95d003ed5
			...
			95a12a8285
		
	
		
							
								
								
									
										25
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								README.md
									
									
									
									
									
								
							| @ -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 | read, the streaming behavior is **_slightly different_** from that of | ||||||
| `request.js`. | `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 | ```js | ||||||
| var request = require('@root/request'); | var request = require('@root/request'); | ||||||
| 
 | 
 | ||||||
| var resp = await request({ | var resp = await request({ | ||||||
|     url: 'http://www.google.com', |     url: 'http://www.google.com', | ||||||
|     stream: true // true | 'filename.ext' | stream.Writable |     stream: true | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| // 'resp' itself is a ReadableStream |  | ||||||
| resp.on('data', function () { | resp.on('data', function () { | ||||||
|     // got some data |     // got some data | ||||||
| }); | }); | ||||||
| @ -79,8 +64,8 @@ resp.on('end', function () { | |||||||
|     // the data has ended |     // the data has ended | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| // 'resp.stream' is a Promise that is resolved when the read stream is destroyed | // resp.stream is a Promise that is resolved when the read stream is destroyed | ||||||
| await resp.stream; // returns `undefined` | await resp.stream; | ||||||
| console.log('Done'); | console.log('Done'); | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| @ -141,12 +126,12 @@ request.post('http://service.com/upload').form({key:'value'}) | |||||||
| 
 | 
 | ||||||
| #### multipart/form-data (Multipart Form Uploads) | #### 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: | To use `form-data`, you must install it separately: | ||||||
| 
 | 
 | ||||||
| ```bash | ```bash | ||||||
| npm install --save form-data@2.x | npm install --save form-data@2 | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| ```js | ```js | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user