Skip to content

Commit 392dad0

Browse files
committed
Add two more examples.
1 parent 503109f commit 392dad0

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

readme.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,49 @@ const options = {
144144
await 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

149192
You can install this package using npm:

0 commit comments

Comments
 (0)