undici icon indicating copy to clipboard operation
undici copied to clipboard

No examples in the docs on methods other that GET

Open psytechno604 opened this issue 3 years ago • 2 comments

How to send POST?

There is a "method" option in all Dispatcher's methods, there is also a "body" option described for some of them:

body string | Buffer | Uint8Array | stream.Readable | Iterable | AsyncIterable | null (optional) - Default: null

  • so, "body" cannot be an object. But with https/fetch/axios/etc we can easily send an object via POST. How to do it with undici? JSON.stringify, escaping, base64 encoding - what is exactly a way?

psytechno604 avatar Jan 24 '22 15:01 psytechno604

This is a really good issues for newcomers!

This is a good place to start: https://github.com/nodejs/undici/blob/34cb4c674ec97f5a353298c2fe136f3e65cdbaa8/test/promises.js

mcollina avatar Jan 25 '22 17:01 mcollina

for me it worked with simple JSON.stringify(body) and headers['content-type'] = 'application/json'.

psytechno604 avatar Feb 01 '22 14:02 psytechno604