# RESTful parameters - Why input parameters are so "webish"?

**URL:** <https://www.ruby-forum.com/t/restful-parameters-why-input-parameters-are-so-webish/92616>\
**Category:** Rails\
**Created:** [April 21, 2007, 4:20pm UTC](https://www.ruby-forum.com/t/restful-parameters-why-input-parameters-are-so-webish/92616 "2007-04-21T16:20:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jetienne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jetienne](https://www.ruby-forum.com/u/jetienne)\
**Post date:** [April 21, 2007, 4:20pm UTC](https://www.ruby-forum.com/t/restful-parameters-why-input-parameters-are-so-webish/92616/1 "2007-04-21T16:20:25Z")

</div>

Hi,

Using Rails 1.2.3, I would like to know if it is possible to set the  
format of parameters for a POST call.

Like you have:

# GET /assets/#

def show  
@asset = Asset.find(params[:asset])  
respond\_to |format|  
format.html  
format.xml {render :xml =\> @asset.xml}  
end  
end

why the format of params[:asset] in

# POST /assets

def assets  
@asset = Asset.new(params[:asset])  
…  
end

needs to have a very “webish” format:  
“asset[title]=foo&asset[description]=bar” ? Why not xml/json? Is it  
possible to have a prefilter to accept xml, json …? Or better,  
formatting the input parameters according to Accept header value? If it  
is not supported, how would you intercept the parameters to convert them  
from xml/json to this array format ?

Regards,  
Jean-Etienne

---

<div class="post-metadata">

**Author:** ![jetienne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jetienne](https://www.ruby-forum.com/u/jetienne)\
**Post date:** [April 21, 2007, 5:26pm UTC](https://www.ruby-forum.com/t/restful-parameters-why-input-parameters-are-so-webish/92616/2 "2007-04-21T17:26:22Z")

</div>

On 4/21/07, Jean-Etienne D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> respond\_to |format|  
> …  
> end
> 
> needs to have a very “webish” format:  
> “asset[title]=foo&asset[description]=bar” ? Why not xml/json? Is it  
> possible to have a prefilter to accept xml, json …? Or better,  
> formatting the input parameters according to Accept header value? If it  
> is not supported, how would you intercept the parameters to convert them  
> from xml/json to this array format ?

Sure can! You can post XML (the same format as the @asset.to\_xml  
output) if you set the content-type to application/xml, or append a  
.xml extension. ActiveResource works like this. There’ s a param  
parser for Mime::XML that parses the xml and returns a hash in the  
same format, so your controller code doesn’t need to change. All you  
need is a respond\_to block for the response.

I have an experimental plugin for JSON support:  
[http://svn.techno-weenie.net/projects/plugins/json\_for\_rails](http://svn.techno-weenie.net/projects/plugins/json_for_rails), but  
there are a few issues:

- It uses the fjson gem (fast json parser written in c). I seem to  
recall rails has this now, buy converting json to YAML and returning  
that.
- json has no date/time literal. If you look at my plugin, it looks  
for any strings in the xmlschema format and parses them to date/times.  
But, this is a hack. Currently there’s no standard for times in  
json, so I don’t really think json is suitable for this task. You can  
come up with your own convention if you like, or just use XML and get  
on with your app.
- set up a simple json param parser. This would be a good guide if  
you wanted a simple way to process other common formats, for example.

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![jetienne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jetienne](https://www.ruby-forum.com/u/jetienne)\
**Post date:** [April 21, 2007, 7:16pm UTC](https://www.ruby-forum.com/t/restful-parameters-why-input-parameters-are-so-webish/92616/3 "2007-04-21T19:16:33Z")

</div>

Hi,

This is what I tought at the beginning, I tried to pass the xml I got  
from a GET (application/xml, not assets.xml) but with no luck. Checking  
the logs, the xml is understood as a simple string…

I remind you I am not working on Rails…

Regards,
