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 | ||||
| `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 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user