I'm trying to create a route with Sinatra that only accepts POST with an Content-type: application/json
without success.
My approach is as follows:
post '/dogs', :provides => :json do
# returns here a json response
end
Testing with curl, I have seen that :provides => :json
configures the route to respond with an Content-Type: application/json
.
That's right because I want also to respond with a JSON message to the POST request but I really need that this route only respond to POST requests with a Content-Type: application/json
and not, for example, to others (e.g. Content-Type: application/xml
).
Is there any way in Sinatra to restrict the route to only accept requests with a certain Content-Type
?