I made a POST request to a Sinatra app. I noticed that the parameters arrive in the server as a StringIO. It can be read using request.body.read
. However, it can only be read once. To read it again, I need to run request.body.rewind
(haha, Sinatra).
Why is it designed this way? I can see this being useful in streaming data but are there other applications?
Parameters are available within Sinatra via the params hash. request.body.read
and request.body.rewind
are part of Rack, they are not actually implemented within Sinatra. The most common way I have used this in the past is when I'm using Sinatra strictly as a web API and serializing/de-serializing my payload.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With