# Ruby web service

**URL:** <https://www.ruby-forum.com/t/ruby-web-service/185998>\
**Category:** Ruby\
**Created:** [March 30, 2010, 9:42am UTC](https://www.ruby-forum.com/t/ruby-web-service/185998 "2010-03-30T09:42:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bradphelan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/aeb1de/32.png) [@bradphelan](https://www.ruby-forum.com/u/bradphelan)\
**Post date:** [March 30, 2010, 9:42am UTC](https://www.ruby-forum.com/t/ruby-web-service/185998/1 "2010-03-30T09:42:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bradphelan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/aeb1de/32.png) [@bradphelan](https://www.ruby-forum.com/u/bradphelan)\
**Post date:** [March 30, 2010, 12:52pm UTC](https://www.ruby-forum.com/t/ruby-web-service/185998/2 "2010-03-30T12:52:10Z")

</div>

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 🙂 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”}}}
