> 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.
> ...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.
Ah, didn't get that context; your clarification is appreciated. Though I'm not sure kids these days care about progressive enhancement-style webdev ...
> 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
> 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.
reply