3 ms·
Why doesn't the example he criticizes use a plain text request body when it's only a single parameter anyway? And is he seriously recommending HTTP FORM POST da
by tannhaeuser 5y ago
Why doesn't the example he criticizes use a plain text request body when it's only a single parameter anyway? And is he seriously recommending HTTP FORM POST data as a best practice to send API request/responses when you're using JavaScript? At the end he even touts the ability to convert the request to JSON (well, technically, to a JavaScript object). But porquoi when you could send an application/json request in the first place?
- afavour 5y ago> And is he seriously recommending HTTP FORM POST data as a best practice to send API request/responses when you're using JavaScript? I don’t think so? I think sending JSON POST data is a solved problem, so to speak: everyone already knows how to do it. The evidence suggests the same is not true for form data.
- jaffathecake 5y agoHi, I'm the "he". > Why doesn't the example he criticizes use a plain text request body when it's only a single parameter anyway? The API supports other params, namely "language" http://text-processing.com/docs/sentiment.html http://text-processing.com/docs/sentiment.html > And is he seriously recommending HTTP FORM POST data as a best practice to send API request/responses when you're using JavaScript? If the API only accepts a URL encoded body then I absolutely recommend sending a URL encoded body. If you're in control of the API endpoint, then you can pick whatever format you want. An HTML form can send data as application/x-www-form-urlencoded, multipart/form-data, or text/plain (although that's useless in practice). If you're progressively enhancing a form, you might want to gather the data in the same format as would otherwise be submitted. You could send it in that format with JavaScript, or convert it to another format (there's a whole section about that at the end of the article). I recommend using multipart/form-data if you need to send file data along with other values. You'll have a bad time trying to send this as JSON. This recommendation is right at the end of the article.
- wayneftw 5y ago> ...if you need to send file data along with other values. You'll have a bad time trying to send this as JSON. Does anyone think it's ever a good idea to post files and form data all at the same time, to the same endpoint? That right there seems like an exceptionally bad idea. Typically I would generate signed upload URLs for clients to upload files directly to some bucket and the submitted form data would contain only pointers to those uploads.
- jaffathecake 5y agoThat's absolutely an option. Decent tooling allows streaming processing of multipart/form-data, so there might not be a ton of benefit. I guess it depends on your server set up.
- tannhaeuser 5y ago> progressively enhancing a form Ah, didn't get that context; your clarification is appreciated. Though I'm not sure kids these days care about progressive enhancement-style webdev ...
- jaffathecake 5y agoHeh yeah. It's been 8 years since my last "hey progressive enhancement is still important" blog post. Almost time for another!