Reputation: 87
Context
I've written a JS function that sends a POST request to my API endpoint with the contents of an image file. Part of the requirement is to also send file-related information as part of the request. Encoding the request as multipart is not an option for me, so the solution I've written involves putting the information as part of the request headers.
Question
I noticed on a related question that this approach is not suggested as an option, so I'm wondering if my solution is not considered a good practice and if there's any potential downsides. So far the code I wrote works as expected, but I wanted to gut check here.
Upvotes: 0
Views: 870
Reputation: 99571
Adding information about the HTTP request to the header is not entirely without precedence. For instance, you could consider that Content-Type
, Title
, Link
isn't just 'meta-data', it's relevant data.
I don't think there's anything in the specifications that explicitly forbid this. I think the biggest issue with it is that it's 'surprising' behavior, and it's good to try to build API's that are the least unique and/or surprising.
Some random alternatives, not necessarily in order of preference.
I'll leave it up to you to decide what's best, but I don't think there's anything non-standard about what you're doing.
Upvotes: 1