I am creating an API using grape.
(I don't use other frameworks such as ruby on rails or sinatora .grape alone.)
Check the content-type of the http header in the request and determine if the value is
application/x-www-form-urlencoded.
I'd like to cut through the process, but I don't know how to do it.
The header ['Content-Type'] could not retrieve the value.
A solution using the rack mechanism ("You can write like this on config.ru") is fine.
ruby grape rack
Self-resolved.
class MyRackMiddleware
def initialize (app)
@app=app
end
def call(env)
unless env ["CONTENT_TYPE"] == 'application/x-www-form-urlencoded'
raise
end
@ app.call(env)
end
end
↑ I could have created middleware like this and called it inside config.ru.
use MyRackMiddleware
run API
© 2024 OneMinuteCode. All rights reserved.