Where did this agreement come from Ruby?

There, the part of the Ruby middleware used by Rails and other frameworks analyzes the parameters that you sent to the server into a nested Hash object.

If you send these parameters to the server:

 person[id] = 1 person[name] = Joe Blow person[email] = joe.blow@test.com person[address][street_address] = 123 Somewhere St. person[address][city] = Chicago person[address][zip] = 12345 person[other_field][] = 1 person[other_field][] = 2 person[other_field][] = 3 

They are analyzed as follows:

 { :person => { :id => "1", :name => "Joe Blow", :email => " joe.blow@test.com ", :address => { :street_address => "123 Somewhere St.", :city => "Chicago", :state => "IL", :zip => "12345" }, :other_field => [ 1, 2, 3 ] } } 

I believe this is also supported by PHP. Can someone tell me what is called this agreement, where did it come from, and what other languages โ€‹โ€‹support it? (Perl, Python, etc.)

+7
source share
3 answers

Field studies

Iโ€™m trying to find out if there is a name for this agreement, but I canโ€™t find it yet.

ruby

What it's worth is the piece of middleware that does this in Ruby, Rack::Utils . See the source on Github .

The Ruby on Rails manual has more information on the topic .

And here's an interesting ticket about moving code from Rails to Rack middleware.

Php

I did some digging in the PHP source and it seems like all the magic happens in the main/php_variables.c source file. The SAPI code calls the php_std_post_handler method defined here. This ultimately calls the php_register_variable_ex method, which is 185 lines of complex string parsing in C (I have to admit that C is not my strongest).

The only name I could find here is php_std_post_handler , the standard PHP POST handler.

Python

In Python, this format is not supported by default. See https://stackoverflow.com>

Perl

The Perl CGI library also does not support this format. This gives easy access to one or more values, but not to nested values, as in your example. See the documentation for fixing the value or values โ€‹โ€‹of a single named parameter and selecting a parameter list as a hash .

Java

Check out the heated debate about parsing query parameters in this question . Java does not parse this "nested format" of the default POST parameters in the data structure.

Conclusion

I reviewed this and did not find a single name for this method of parameter analysis. Of the languages โ€‹โ€‹I've looked at, only Ruby and PHP support this format natively.

+7
source

He called nothing, AFAIK, except for "sending parameters." In any case, it is called the "[type] conversion" parameter, where Rails simply "converts" it to a hash.

Other structures go further, using parameter names as expressions used to create typed objects initialized with parameter values โ€‹โ€‹converted by type.

All parameters are a string value with a name. Any / all structure is imposed by the language / structure used on the server side; that it transforms is 100% dependent on this language / framework, and what this transformation consists of will determine that it will be (reasonably) called.

+2
source

which would be a JSON object, which is pretty standard and supported by most languages โ€‹โ€‹/ libraries these days.

0
source

All Articles