Skip to content

Commit

Permalink
Add FormData with streams usage example
Browse files Browse the repository at this point in the history
Based on climba03003 example from here nodejs#2202 (comment)
  • Loading branch information
JaoodxD committed Apr 10, 2024
1 parent 6bfc2e8 commit 661061b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docs/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,33 @@ async function postFormRequest (port = 3001) {
}
```

### A FormData request with file stream, read the response body as text

```js
const { request } = require('undici')
const { openAsBlob } = require('fs')

async function formDataBlobRequest () {
// Make a FormData request with file stream:

const formData = new FormData()
formData.append('field', 42)
formData.set('file', await openAsBlob('./index.mjs'))

const response = await request('http://127.0.0.1:3000', {
method: 'POST',
body: formData
})
console.log(await response.body.text())

const data = await body.text()
console.log('response received', statusCode)
console.log('headers', headers)
console.log('data', data)
}

```

### A DELETE request
```js
const { request } = require('undici')
Expand Down

0 comments on commit 661061b

Please sign in to comment.