How to parse JSON request body in Sinatra just once and expose it to all routes?

前端 未结 5 1949
暗喜
暗喜 2020-12-15 16:12

I am writing an API and it receives a JSON payload as the request body.

To get at it currently, I am doing something like this:

post \'/doSomething\'         


        
5条回答
  •  执笔经年
    2020-12-15 16:16

    You can also use Rack Middleware to parse it. See https://github.com/rack/rack-contrib Just use Rack::PostBodyContentTypeParser when initializing your Sinatra class.

提交回复
热议问题