Ruby web service

Hi all,

I’m looking to make a web service probably with Sinatra. I’m a little
confused about the best way to structure parameter passing for POST /
PUT. I’d like to use XML formats for the data. I’ve found the
‘active_record’ Hash.to_xml and Hash.from_xml and I’m happy to settle
for that choice of encoding.

However I see two ways of doing constructing the POST/PUT body.

(a) Posting the XML parameter as the body of the post using an XML
content type
(b) Using URL encoding and setting a parameter

xml=…

Can I choose either approach or do I need to support both?

Regard Brad

bradphelan wrote:

However I see two ways of doing constructing the POST/PUT body.

(a) Posting the XML parameter as the body of the post using an XML
content type
(b) Using URL encoding and setting a parameter

xml=…

Can I choose either approach or do I need to support both?

It’s your app and your users, so you get to choose :slight_smile: But (a) is the
standard way to handle XML uploads.

If you want to handle form data, note that Rack/Sinatra/Rails support
nested form elements, so for example

a[b][c]=1&a[b][d]=2

will give you params = {“a”=>{“b”=>{“c”=>“1”,“d”=>“2”}}}

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs