I want to return raw data/blob from my grape/rest api.
I followed the thread at : https://github.com/intridea/grape/issues/412
for a code like :
get 'foo' do
content_type 'text/plain'
"hello world"
end
1) I used : format 'txt' - I got quoted text like : "hello world" no error on the browser though, curl gives Content-Type: text/plain but the quotes are not removed
2) env['api.format'] = :txt gives error in browser
3) content_type :txt, 'text/plain' gives error in browser wrong number of args
Any other ways to fix this ?
Thanks.
Here's what worked for me:
get 'foo' do
content_type 'text/plain'
env['api.format'] = :binary
body 'Stuff here'
end
The documentation says:
env['api.format'] = :binary # there's no formatter for :binary, data will be returned "as is"
So as long as you don't override the :binary
formatter, you should be fine.
According to this you can do the following:
class API < Grape::API
get 'foo' do
content_type 'text/plain'
body 'hello world'
end
end
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