[Nitro] param handling

Jonathan Buch john at oxyliquit.de
Mon Oct 23 07:54:53 EDT 2006


Hi,

this is a question, Nitro handles params.  Please think about this a bit,
and tell us (George and me) what you think would be the correct way.
Normally you won't have any problems with params and either way works
well when used in certain ways.


Short example of the used method to describe requests in this mail:

     def action(par1, par2)
     GET /action/1/2

With this action-method and request it will lead to the result:

     { :arguments => [1, 2], :params => {} }

So, arguments are used to call the `def action()` with, params can be accessed
via the `request.params` hash.


Now, on how to handle params:


### should GET parameter get mixed into arguments?

     def action(par1 = nil, par2 = nil)
     GET /action?par1=foo;par2=bar

We have 2 possibilities:

     {:arguments => [1, 2], :params => {} }
     {:arguments => [nil, nil], :params => {'par1' => 'foo', 'par2' => 'bar'} }

George wants the first to be possible, I don't.

Problems:

* How is decided, which parameters get mixed into the arguments?
* What about `GET /action/1?par1=foo`
* What about `GET /action/1/2/par1=foo;par2=bar`
* What about `GET /action?par2=bar;par1=foo`
* What about `GET /action?par1=bar;par1=bar1;par2=foo`
* What about POST params?

In my opinion, the GET parameters is a hash, not an array which is in any
particular order and thus can not be expected to be merged into the arguments
in the correct order.
The usage of `par1` and `par2` as parameters is misleading due to them being
the same as the action arguments.

It (together with the next param problem) can lead to annoying problems and
workarounds when used in certain ways.  Read my earlier mails on this subject.


Secondly:

### Strict param requirements?

     def action(par1, par2)
     GET /action

We have again 2 possibilities to handle this situation:

     { :arguments => [nil, nil], :params => {} }
     return error

George also wants the first to be possible.

Problems with the first approach:

* More error checking needed within the `action()` method.
* The first can also be created by normal Ruby means:
   `def action(par1 = nil, par2 = nil)`


So, please think about the following:

* Should the param mixing be possible?
* Should the param requirements be strict?

Thanks for taking the time,

Jonathan

-- 
Feel the love
http://pinkjuice.com/pics/ruby.png


More information about the Nitro-general mailing list