[Nitro] param handling

Thomas Leitner t_leitner at gmx.at
Tue Oct 24 03:09:16 EDT 2006


I'm quite new to Nitro but I would like to contribute, and I think this
is a good way to start :-)

| ### 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'} }

I don't think the first possibility is a good idea because, like
Jonathan said, parameters in query strings are inherently unordered.
However, if Ruby would support named parameters, or, if one could
annotate the method so that Nitro could find out in which order it has
to provide the params, I would rather like the first possibility. 
Something like

      ann :action, :params => %w[par2 par1]
      def action(par2, par1)

Also, I think there is a routing facility available in Nitro - what if
the route to the method changes? Would there be a problem with the first

| ### 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)`

I would vote for the first possibility here because if it happens that
an action is called without the required parameters, the developer could
respond with an error message that exactly fits the error. The second
possibility would just return a general "too few arguments" error.

This also raises the question how far Nitro should check for errors:
with the first possibility it would be on action level, with the second
on parameter level which is just one level deeper. I think that
checking on action level is enough.

Just my two cents,

More information about the Nitro-general mailing list