Mercurial > hg > nginx-site
comparison xml/en/docs/njs/reference.xml @ 2872:1e1a15c84515
Extended description of r.args in njs reference.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Tue, 19 Jul 2022 16:53:00 +0100 |
parents | c8d57f14c51b |
children | b4eb565bbb1f |
comparison
equal
deleted
inserted
replaced
2871:ca4adc1068f0 | 2872:1e1a15c84515 |
---|---|
7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> | 7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> |
8 | 8 |
9 <article name="Reference" | 9 <article name="Reference" |
10 link="/en/docs/njs/reference.html" | 10 link="/en/docs/njs/reference.html" |
11 lang="en" | 11 lang="en" |
12 rev="82"> | 12 rev="83"> |
13 | 13 |
14 <section id="summary"> | 14 <section id="summary"> |
15 | 15 |
16 <para> | 16 <para> |
17 <link doc="index.xml">njs</link> provides objects, methods and properties | 17 <link doc="index.xml">njs</link> provides objects, methods and properties |
45 | 45 |
46 <list type="tag"> | 46 <list type="tag"> |
47 | 47 |
48 <tag-name id="r_args"><literal>r.args{}</literal></tag-name> | 48 <tag-name id="r_args"><literal>r.args{}</literal></tag-name> |
49 <tag-desc> | 49 <tag-desc> |
50 request arguments object, read-only | 50 request arguments object, read-only. |
51 <para> | |
52 The query string is returned as an object. | |
53 Since <link doc="changes.xml" id="njs0.7.6">0.7.6</link>, | |
54 duplicate keys are returned as an array, | |
55 keys are case-sensitive, both keys and values are percent-decoded. | |
56 </para> | |
57 | |
58 <para> | |
59 For example, the query string | |
60 <example> | |
61 'a=1&b=%32&A=3&b=4&B=two%20words' | |
62 </example> | |
63 is converted to <literal>r.args</literal> as: | |
64 <example> | |
65 {a: "1", b: ["2", "4"], A: "3", B: "two words"} | |
66 </example> | |
67 More advanced parsing scenarios can be achieved with the | |
68 <link id="querystring">Query String</link> module | |
69 and with the | |
70 <link doc="../http/ngx_http_core_module.xml" id="var_args"><literal>$args</literal></link> | |
71 variable, for example: | |
72 | |
73 <example> | |
74 import qs from 'querystring'; | |
75 | |
76 function args(r) { | |
77 return qs.parse(r.variables.args); | |
78 } | |
79 </example> | |
80 The argument object | |
81 is evaluated at the first access to <literal>r.args</literal>. | |
82 If only a single argument is needed, for example <literal>foo</literal>, | |
83 <link doc="../varindex.xml">nginx variables</link> can be used: | |
84 <example> | |
85 r.variables.arg_foo | |
86 </example> | |
87 Here, <link id="r_variables">nginx variables object</link> | |
88 returns the first value for a given key, | |
89 case-insensitive, without percent-decoding. | |
90 </para> | |
91 | |
92 <para> | |
93 To convert <literal>r.args</literal> back to a string, | |
94 the Query String | |
95 <link id="querystring_stringify"><literal>stringify</literal></link> | |
96 method can be used. | |
97 </para> | |
51 </tag-desc> | 98 </tag-desc> |
52 | 99 |
53 <tag-name id="r_done"><literal>r.done()</literal></tag-name> | 100 <tag-name id="r_done"><literal>r.done()</literal></tag-name> |
54 <tag-desc> | 101 <tag-desc> |
55 after calling this function, | 102 after calling this function, |