undici
undici copied to clipboard
No examples in the docs on methods other that GET
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?
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
for me it worked with simple JSON.stringify(body) and headers['content-type'] = 'application/json'.