lapis
lapis copied to clipboard
"Content-Type" check
Is there a way to tell that an endpoint can only be invoked with a specific Content-Type, and if the Content-Type doesn't match it returns a 415 Unsupported Media Type response ?
There is no built in helper for doing that, but it should be fairly easy to write your own. @req.headers holds the request headers. I can write an example if you want.
I've implemented the functionality by manually checking req.headers.
As a feature request, it would be nice if the framework could handle that in a helper to make it possible to implement endpoints that accept specific content types.
@thefosk What would you like such a thing to look like? Something like:
class extends lapis.Application
[upload: "/upload"]: respond_to {
POST: content_type {
["image/jpeg"]: =>
do_something!
? (Note: I have no idea if that syntax could even work..just guessing based on my usage of json_params and respond_to. :sweat_smile:)