Implementing a single html endpoint

410 views
Skip to first unread message

Emil Kampp

unread,
Jul 29, 2014, 2:28:37 AM7/29/14
to ruby-...@googlegroups.com
Hi there. 

I need to render a single html endpoint in my grape app. I have looked around and found Rack::Static, but my page isn't static, it will contain some dynamic content generated by the grape controller. 

How would I go about implementing such a single html endpoint? I have tried with the format :html and content_type :html, but neither seems to work, so I must be missing a point somewhere. 

Cheers, 

Emil

Daniel Doubrovkine

unread,
Jul 29, 2014, 7:34:38 AM7/29/14
to ruby-...@googlegroups.com
Serving html is like any other content (here's an example that serves text: https://github.com/dblock/grape-on-rack/blob/master/api/content_type.rb).

The HTML content type is `text/html`, so add `content_type :html, 'text/html'` to the API and either `format :html` to the entire API endpoint or `content_type 'text/html'` inside the specific implementation. Also use some kind of renderer like HAML or ERB to generate the template.




--
You received this message because you are subscribed to the Google Groups "Grape Framework Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-grape+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

dB. | Moscow - Geneva - Seattle - New York
code.dblock.org - @dblockdotorg - artsy.net - github/dblock

Emil Kampp

unread,
Jul 29, 2014, 7:37:12 AM7/29/14
to ruby-...@googlegroups.com

Yes, I have solved it. It turns out you need the content_type and stuff in the before block, not inside the method :) Silly me.

Thanks for your help!



-- 
Emil Kampp
IT Entrepenour and founder
You received this message because you are subscribed to a topic in the Google Groups "Grape Framework Discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ruby-grape/FCbK0dFvHAU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ruby-grape+...@googlegroups.com.

Fernanda

unread,
Dec 7, 2018, 10:41:22 AM12/7/18
to Grape Framework Discussion
Hi Emil,

I know this is very old, but can you share an example of how you're retuning the HTML? I am trying to render the erb template from a rails controller, send to the endpoint to use as response. But this does not seem to work and I can only send it as text.
Any help would be greatly appreciated. 

Thanks!
Fernanda
Reply all
Reply to author
Forward
0 new messages