Remove quotes from returned string of grapes api

I want to return raw data / blob from my crop / rest api.

I followed the thread: https://github.com/intridea/grape/issues/412

for code like:

get 'foo' do
  content_type 'text/plain'
  "hello world"
end

      

1) I used: format 'txt' - I got quoted text like: "hello world" errors in the browser, although, 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 arguments

Any other ways to fix this?

Thank.

+3


source to share


3 answers


Using the content_type :txt, 'text/plain'

above method and using the method body

worked for me. Here is my code snippet:



content_type :txt, "text/plain" desc "ping pong" get "/ping" do challenge = params["hub.challenge"] challenge = "pong" if challenge.to_s.empty? status 200 body challenge end

+1


source


According to this, you can do the following:



class API < Grape::API
  get 'foo' do
    content_type 'text/plain'
    body 'hello world'
  end
end

      

0


source


You don't need to use the "body", all that's left to do is add one line to the API class (above this method):

content_type :txt, 'text/plain'

      

So Grape uses: txt formatter for all endpoints that serve text / regular content

0


source