ESP32 HTTPS Server: httpsserver::ResourceParameters Class Reference
The ResourceParameters provide access to the parameters passed in the URI. More...
#include <ResourceParameters.hpp>
Public Member Functions | |
| bool | isQueryParameterSet (std::string const &name) |
| Checks whether a specific HTTPS query parameter is set. More... | |
| bool | getQueryParameter (std::string const &name, std::string &value) |
| Returns an HTTP query parameter. More... | |
| std::vector< std::pair< std::string, std::string > >::iterator | beginQueryParameters () |
| Provides iterator access to the query parameters. More... | |
| std::vector< std::pair< std::string, std::string > >::iterator | endQueryParameters () |
| Counterpart to beginQueryParameters() for iterating over query parameters. | |
| size_t | getQueryParameterCount (bool unique=false) |
| Returns the number of query parameters. More... | |
| bool | getPathParameter (size_t const idx, std::string &value) |
| Checks for the existence of a path parameter and returns it as string. More... | |
| std::string | getPathParameter (size_t const idx) |
| Directly returns a path parameter. More... | |
Protected Member Functions | |
| void | setQueryParameter (std::string const &name, std::string const &value) |
| void | resetPathParameters () |
| void | setPathParameter (size_t idx, std::string const &val) |
Friends | |
| class | ResourceResolver |
The ResourceParameters provide access to the parameters passed in the URI.
There are two types of parameters: Path parameters and query parameters.
Path parameters are the values that fill the asterisk placeholders in the route definition of a ResourceNode.
Query parameters are the key-value pairs after a question mark which can be added to each request, either by specifying them manually or as result of submitting an HTML form with a GET as method property.
◆ beginQueryParameters()
| std::vector< std::pair< std::string, std::string > >::iterator httpsserver::ResourceParameters::beginQueryParameters | ( | ) |
Provides iterator access to the query parameters.
Query parameters are key-value pairs that are appended to the URI after a question mark.
If you want just a specific parameter, have a look at getQueryParameter()
The iterator will yield pairs of std::string, of which the first value specifies the query parameter key and the second value corresponds to the query parameters value. If the entry is value-less, the second value will be the empty string.
If the same key is used multiple times in the query, the iterator will yield it multiple times, once for each occurence with the specific value.
- Returns
- Iterator over std::pairs of std::strings that represent (key, value) pairs
◆ getPathParameter() [1/2]
| bool httpsserver::ResourceParameters::getPathParameter | ( | size_t const | idx, |
| std::string & | value | ||
| ) |
Checks for the existence of a path parameter and returns it as string.
Path parameters are defined by an asterisk as placeholder when specifying the path of the ResourceNode and addressed by an index starting at 0 for the first parameter.
For values of idx that have no matching placeholder, value is left unchanged and the method will return false.
- Parameters
-
idx Defines the index of the parameter to return, starting with 0. value The value is written into this parameter.
- Returns
- true iff the value could be written.
◆ getPathParameter() [2/2]
| std::string httpsserver::ResourceParameters::getPathParameter | ( | size_t const | idx | ) |
Directly returns a path parameter.
Path parameters are defined by an asterisk as placeholder when specifying the path of the ResourceNode and addressed by an index starting at 0 for the first parameter.
This method will return the parameter specified by the index. The caller is responsible to assure that the index exists. Otherwise, an empty string will be returned.
- Parameters
-
idx Defines the index of the parameter to return, starting with 0.
- Returns
- the value of the placeholder
◆ getQueryParameter()
| bool httpsserver::ResourceParameters::getQueryParameter | ( | std::string const & | name, |
| std::string & | value | ||
| ) |
Returns an HTTP query parameter.
Query parameters are key-value pairs that are appended to the URI after a question mark.
The name parameter specifies the name of the query parameter to retrieve. If it is set, the value is written to the value parameter and true is returned. If the parameter does not exist, value is left unchanged and false is returned. If the parameter is used without a value, an empty string is written to value and true is returned.
- Parameters
-
name The name of the parameter to retrieve. If the parameter exists multiple times, the first occurence is used for the value. Use beginQueryParameters() to retrieve all values. value The target to write the value to, if the parameter exists.
- Returns
- true iff the parameter exists and the corresponding value has been written.
◆ getQueryParameterCount()
| size_t httpsserver::ResourceParameters::getQueryParameterCount | ( | bool | unique = false | ) |
Returns the number of query parameters.
Query parameters are key-value pairs that are appended to the URI after a question mark.
- Parameters
-
unique If true, return the number of unique keys (using the same key multiple times is counted only once). False by default, as checking for uniqueness is not efficient.
- Returns
- Number of query parameters
◆ isQueryParameterSet()
| bool httpsserver::ResourceParameters::isQueryParameterSet | ( | std::string const & | name | ) |
Checks whether a specific HTTPS query parameter is set.
Query parameters are key-value pairs that are appended to the URI after a question mark.
If the key exists (either as a value-less parameter or with a value), the function returns true.
- Parameters
-
name The parameter to check
- Returns
- true iff the parameter exists
The documentation for this class was generated from the following files:
- /home/frank/Projekte/esp32/https_server/esp32_https_server/src/ResourceParameters.hpp
- /home/frank/Projekte/esp32/https_server/esp32_https_server/src/ResourceParameters.cpp