Class search
Ada URL search parameters
See: https://url.spec.whatwg.org/#interface-urlsearchparams
Decode Methods
search:decode () | Decodes search parameters and returns a Lua table of them. |
search:decode () | Decodes all search parameters and returns a Lua table of them. |
Has Methods
search:has (key) | Checks whether the search has a key. |
search:has_value (key, value) | Checks whether the search has a key with a specific value. |
Get Methods
search:get (key) | Get search parameter’s value. |
search:get_all (key) | Get all the search parameter’s values. |
Set Methods
search:reset (search) | Sets (or resets) the search parameters. |
search:set (key, value) | Set the search parameter’s value. |
search:append (key, value) | Append value to the the search parameter. |
Other Methods
search:tostring () | Return search parameters as a string. |
search:sort () | Sort search parameters. |
search:size () | Count search parameters. |
Meta Methods
search:__pairs () | Iterate over each key and value in search parameters. |
search:__pairs () | Iterate over each parameter in search parameters. |
search:__tostring () | Return search parameters as a string. |
search:__len () | Count search parameters. |
Destructor Method
search:free () | Explicitly destroys the Ada URL Search instance and frees the memory. |
Remove Methods
search:remove (key) | Remove search parameter. |
search:remove_value (key, value) | Remove search parameter’s value. |
Iterate Methods
search:each () | Iterate over search parameters. |
search:each_key () | Iterate over each key in search parameters. |
search:each_value () | Iterate over each value in search parameters. |
search:pairs () | Iterate over each key and value in search parameters. |
search:ipairs () | Iterate over each parameter in search parameters. |
Decode Methods
- search:decode ()
-
Decodes search parameters and returns a Lua table of them.
If same parameter appears multiple times, only the value of the first is returned.
An example return value: { key1 = “value”, key2 = “value2”, }
Returns:
-
table
a table of all search parameters (a string:string map).
Usage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f&a=g") local result = search:decode()
- search:decode ()
-
Decodes all search parameters and returns a Lua table of them.
An example return value: { key1 = { “first”, “second”, }, key2 = { “value” }, }
Returns:
-
table
a table of all search parameters (a string:table [array] map).
Usage:
local search = require("resty.ada.search").parse("a=b&a=c&d=e") local result = search:decode_all()
Has Methods
- search:has (key)
-
Checks whether the search has a key.
See: https://url.spec.whatwg.org/#dom-urlsearchparams-has
Parameters:
- key string search parameter name to check
Returns:
-
boolean
true
if search has the key, otherwisefalse
Raises:
error when key is not a stringUsage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") local result = search:has("a")
- search:has_value (key, value)
-
Checks whether the search has a key with a specific value.
See: https://url.spec.whatwg.org/#dom-urlsearchparams-has
Parameters:
Returns:
-
boolean
true
if search has the key with the value, otherwisefalse
Raises:
error when key or value is not a stringUsage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") local result = search:has_value("a", "b")
Get Methods
- search:get (key)
-
Get search parameter’s value.
See: https://url.spec.whatwg.org/#dom-urlsearchparams-get
Parameters:
- key string search parameter name
Returns:
-
string or nil
parameter value or
nil
Raises:
error when key is not a stringUsage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") local result = search:get("a")
- search:get_all (key)
-
Get all the search parameter’s values.
See: https://url.spec.whatwg.org/#dom-urlsearchparams-getall
Parameters:
- key string search parameter name
Returns:
-
table
array of all the values (or an empty array)
Raises:
error when key is not a stringUsage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") local result = search:get_all("a")
Set Methods
- search:reset (search)
-
Sets (or resets) the search parameters.
Parameters:
- search string search to parse
Returns:
-
search
self
Raises:
error when search is not a stringUsage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") print(search:reset("g=h"):tostring())
- search:set (key, value)
-
Set the search parameter’s value.
See: https://url.spec.whatwg.org/#dom-urlsearchparams-set
Parameters:
Returns:
-
search
self
Raises:
error when key or value is not a stringUsage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") local result = search:set("a", "g"):tostring()
- search:append (key, value)
-
Append value to the the search parameter.
See: https://url.spec.whatwg.org/#dom-urlsearchparams-append
Parameters:
Returns:
-
search
self
Raises:
error when key or value is not a stringUsage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") local result = search:append("a", "g"):tostring()
Other Methods
- search:tostring ()
-
Return search parameters as a string.
See: https://url.spec.whatwg.org/#urlsearchparams-stringification-behavior
Returns:
-
string
string presentation of the search parameters
Usage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") local result = search:tostring()
- search:sort ()
-
Sort search parameters.
See: https://url.spec.whatwg.org/#dom-urlsearchparams-sort
Returns:
-
search
self
Usage:
local search = require("resty.ada.search").parse("e=f&c=d&a=b") local result = search:sort():tostring()
- search:size ()
-
Count search parameters.
Returns:
-
number
search parameters count
Usage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") local result = search:size()
Meta Methods
- search:__pairs ()
-
Iterate over each key and value in search parameters.
Returns:
- function iterator function
- cdata state
Usage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") for key, value in pairs(search) do print(key, " = ", value) end
- search:__pairs ()
-
Iterate over each parameter in search parameters.
Returns:
- function iterator function
- cdata state
Usage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") for i, param in ipairs(search) do print(i, ". ", param.key, " = ", param.value) end
- search:__tostring ()
-
Return search parameters as a string.
See: https://url.spec.whatwg.org/#urlsearchparams-stringification-behavior
Returns:
-
string
string presentation of the search parameters
Usage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") local result = tostring(search)
- search:__len ()
-
Count search parameters.
Returns:
-
number
search parameters count
Usage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") local result = #search
Destructor Method
- search:free ()
-
Explicitly destroys the Ada URL Search instance and frees the memory.
After calling this function, further calls will result runtime error. If this is not explicitly called, the memory is freed with garbage collector.
Usage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") search:free()
Remove Methods
- search:remove (key)
-
Remove search parameter.
See: https://url.spec.whatwg.org/#dom-urlsearchparams-delete
Parameters:
- key string search parameter name
Returns:
-
search
self
Raises:
error when key is not a stringUsage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") local result = search:remove("a"):tostring()
- search:remove_value (key, value)
-
Remove search parameter’s value.
See: https://url.spec.whatwg.org/#dom-urlsearchparams-delete
Parameters:
Returns:
-
search
self
Raises:
error when key or value is not a stringUsage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") local result = search:remove_value("a", "b"):tostring()
Iterate Methods
- search:each ()
-
Iterate over search parameters.
Returns:
- function iterator function
- cdata state
Usage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") for param in search:each() do print(param.key, " = ", param.value) end
- search:each_key ()
-
Iterate over each key in search parameters.
Returns:
- function iterator function
- cdata state
Usage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") for key in search:each_key() do print("key: ", key) end
- search:each_value ()
-
Iterate over each value in search parameters.
Returns:
- function iterator function
- cdata state
Usage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") for value in search:each_value() do print("value: ", value) end
- search:pairs ()
-
Iterate over each key and value in search parameters.
Returns:
- function iterator function
- cdata state
Usage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") for key, value in search:pairs() do print(key, " = ", value) end
- search:ipairs ()
-
Iterate over each parameter in search parameters.
Returns:
- function iterator function
- cdata state
Usage:
local search = require("resty.ada.search").parse("a=b&c=d&e=f") for i, param in search:ipairs() do print(param.key, " = ", param.value) end