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

前端 未结 5 1948
暗喜
暗喜 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:25

    Like this working for sinatra 1.4.5

    before do
      if request.body.size > 0
        request.body.rewind
        @params = ActiveSupport::JSON.decode(request.body.read)
      end
    end
    

提交回复
热议问题