Ruby web service.

B

bradphelan

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=<foo>...</foo>

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

Regard Brad
 
B

Brian Candler

bradphelan said:
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=<foo>...</foo>

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

It's your app and your users, so you get to choose :) 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[c]=1&a[d]=2

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top