File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -144,6 +144,49 @@ const options = {
144144await fetch (" https://httpbin.org/post" , options)
145145```
146146
147+ 5 . Speaking of async iterables - if HTTP client supports them, you can use encoder like this:
148+
149+ ``` js
150+ import {Encoder } from " form-data-encoder"
151+ import {FormData } from " formdata-node"
152+
153+ import fetch from " node-fetch"
154+
155+ const fd = new FormData ()
156+
157+ fd .set (" field" , " My hovercraft is full of eels" )
158+
159+ const encoder = new Encoder (fd)
160+
161+ const options = {
162+ method: " post" ,
163+ headers: encoder .headers ,
164+ body: encoder
165+ }
166+
167+ await fetch (" https://httpbin.org/post" , options)
168+ ```
169+
170+ 6 . ...And for those client whose supporting form-data-encoder out of the box, the usage will be much, much more simpler:
171+
172+ ``` js
173+ import {FormData } from " formdata-node" // Or any other spec-compatible implementation
174+
175+ import fetch from " node-fetch"
176+
177+ const fd = new FormData ()
178+
179+ fd .set (" field" , " My hovercraft is full of eels" )
180+
181+ const options = {
182+ method: " post" ,
183+ body: fd
184+ }
185+
186+ // Note that node-fetch does NOT support form-data-encoder
187+ await fetch (" https://httpbin.org/post" , options)
188+ ```
189+
147190# Installation
148191
149192You can install this package using npm:
You can’t perform that action at this time.
0 commit comments