# HG changeset patch # User Yaroslav Zhuravlev # Date 1658245980 -3600 # Node ID 1e1a15c845151d274322ead26c31c261a5b8aecd # Parent ca4adc1068f0ba18c477f9816ce2b798f675fbe0 Extended description of r.args in njs reference. diff -r ca4adc1068f0 -r 1e1a15c84515 xml/en/docs/njs/reference.xml --- a/xml/en/docs/njs/reference.xml Tue Jul 19 19:28:08 2022 +0400 +++ b/xml/en/docs/njs/reference.xml Tue Jul 19 16:53:00 2022 +0100 @@ -9,7 +9,7 @@
+ rev="83">
@@ -47,7 +47,54 @@ r.args{} -request arguments object, read-only +request arguments object, read-only. + +The query string is returned as an object. +Since 0.7.6, +duplicate keys are returned as an array, +keys are case-sensitive, both keys and values are percent-decoded. + + + +For example, the query string + +'a=1&b=%32&A=3&b=4&B=two%20words' + +is converted to r.args as: + +{a: "1", b: ["2", "4"], A: "3", B: "two words"} + +More advanced parsing scenarios can be achieved with the +Query String module +and with the +$args +variable, for example: + + +import qs from 'querystring'; + +function args(r) { + return qs.parse(r.variables.args); +} + +The argument object +is evaluated at the first access to r.args. +If only a single argument is needed, for example foo, +nginx variables can be used: + +r.variables.arg_foo + +Here, nginx variables object +returns the first value for a given key, +case-insensitive, without percent-decoding. + + + +To convert r.args back to a string, +the Query String +stringify +method can be used. + r.done()