3 ms·
> Why doesn't the universal key/value type work for passing a key/values? Because there isn't one? By "itself" (i.e. <form> tags without JS), the browser can
by tehbeard 4y ago
> Why doesn't the universal key/value type work for passing a key/values?
Because there isn't one?
By "itself" (i.e. <form> tags without JS), the browser can POST using two different encoding formats:
- Url encoding (similar to what you'd see in the URI, but as the body of the request)
- multipart/form-data (a derivative of MIME, needed for file uploads)
What's it supposed to do if you passed an object containing a CryptoKey instance, a Blob and a ReadadbleStream??
We also have a ton more ways of encoding and sending data in a POST (which is just the HTTP method, it doesn't convey anything bar that there's probably a body and related headers attached we want the server to do something with).
JSON, XML, CSV, YAML to name but a few key/value formats.
Hell, maybe it's an S3 style endpoint and you just push the raw bytes to save.
fetch is... less "magic" by default. This makes it flexible, but means you have to put just a tiny bit of effort into it.
Or... just use Axios, I ain't your manager; I get by easily enough with a helper js that gets treeshaked out so that I can just call `postJSON(url, body, opts=null)`
- Beltalowda 4y agoYou can default to "application/x-www-form-urlencoded" and use "multipart/form-data" if requested, which is essentially how HTML forms work. There's lots of reasonable behaviours to choose from and you can discus what the best possible approach is, including throwing an exception, but sending "[object Object]" is not one of the reasonable behaviours. > Or... just use Axios, I ain't your manager; I get by easily enough with a helper js that gets treeshaked out so that I can just call `postJSON(url, body, opts=null)` The fact that everyone "just" has to use a wrapper for a basic system API is exactly the problem, especially when this was supposed to be the new shiny thing that would replace the old cruft. Why do I have to add 4 dependencies + 44 "dev dependencies" just to make a HTTP request? Plus, for my personal projects I want to avoid the "npm ecosystem", and I especially want to avoid any JS build system.