I'm building a XML API with the help of the Grape gem. What is the best way to building XML for API actions? Since Grape isn't using standart rails controllers, i can't use views/../xml.builder
. What did you suggest? Maybe there are some best practices for building xml api?
Building XML API with Grape
Asked Answered
Sinece there are no any answers, i will answer my own question. I ended up with modules where are i declare different kind of xml responses and include this modules into my Grape API. In API actions i just calling response methods from this modules. With this approach my code is clear and separated.
@Harriet It was a while ago and we used old grape version, it wasn't parsing our xml correctly to, i made a few changes in the grape. Take a look at my commits in the xml_formatter branches github.com/dpsk/grape/branches maybe it will help you. –
Calais
I have the same problem now and I'm using rabl to render xml but it's not as flexible as xml.builder by far... could you please explain your solution a little further? –
Hynes
@Hynes with which part you have troubles exactly? –
Calais
@Hynes take a look gist.github.com/dpsk/d426fbbadefbc74959c4, it's a simple example on how it can be done. –
Calais
It seems to be sample. Just provide format to tell grape your default format
format :xml
content_type :xml, "text/xml"
Then add .xml
to the end of request url.
© 2022 - 2024 — McMap. All rights reserved.
cannot convert String to xml
error. I make use of content_type :xml, "text/xml". Any suggestions? Thanks! – Harriet