Request Functions
This module contains functions for retrieving information on an HTTP request that has triggered the query. It is mostly useful when building Web Applications.
The module is based on the EXQuery Request Module draft.
- The module will be available if the
basex-api
library is found in the classpath. This is the case if you use one of the complete distributions of BaseX (zip, exe, war). - All functions are assigned to the
http://exquery.org/ns/request
namespace, which is statically bound to the request
prefix. - If any of the functions is called outside the servlet context,
basex:http
is raised.
The following example illustrated what components a URI may consist of (the example is derived from RFC 3986):
foo://example.com:8042/over/there?name=ferret&code=7
\_/ \_________/ \__/\_________/ \________________/
| | | | |
scheme hostname port path query
Signature | request:method() as xs:string |
---|
Summary | Returns the Method of the HTTP request. |
---|
Signature | request:scheme() as xs:string |
---|
Summary | Returns the Scheme component of the URI of an HTTP request. |
---|
Examples | For the example given in the introduction, this function would return foo . |
---|
Signature | request:hostname() as xs:string |
---|
Summary | Returns the Hostname component of the URI of an HTTP request. |
---|
Examples | For the example given in the introduction, this function would return example.com . |
---|
Signature | request:port() as xs:integer |
---|
Summary | Returns the Port component of the URI of an HTTP request, or a default port if it has not been explicitly specified in the URI. |
---|
Examples | For the example given in the introduction, this function would return 8042 . |
---|
Signature | request:path() as xs:string |
---|
Summary | Returns the Path component of the URI of an HTTP request. |
---|
Examples | For the example given in the introduction, this function would return /over/there . |
---|
Signature | request:query() as xs:string? |
---|
Summary | Returns the Query component of the URI of an HTTP request. If no query component exists, an empty sequence is returned. |
---|
Examples | For the example given in the introduction, this function would return name=ferret&code=7 . |
---|
Signature | request:uri() as xs:anyURI |
---|
Summary | Returns the complete URI of an HTTP request as it has been specified by the client. |
---|
Examples | For the example given in the introduction, this method would return foo://example.com:8042/over/there?name=ferret&code=7 . |
---|
Signature | request:context-path() as xs:string |
---|
Summary | Returns the context of the request. For servlets in the default (root) context, this method returns an empty string. |
---|
Signature | request:address() as xs:string |
---|
Summary | Returns the IP address of the server. |
---|
Signature | request:remote-hostname() as xs:string |
---|
Summary | Returns the fully qualified hostname of the client that sent the request. |
---|
Signature | request:remote-address() as xs:string |
---|
Summary | Returns the IP address of the client that sent the request. |
---|
Signature | request:remote-port() as xs:string |
---|
Summary | Returns the TCP port of the client socket that triggered the request. |
---|
Added: New function.
Signature | request:parameter-map() as map(xs:string, item()+) |
---|
Summary | Returns all query and form field parameters available from the HTTP request. With RESTXQ, this function can be used to access parameters that have not been statically bound by %rest:query-param . |
---|
Errors | |
---|
Examples | For the example given in the introduction, this function would return { 'name': 'Ferret' } . |
---|
Signature | request:parameter-names() as xs:string* |
---|
Summary | Returns the names of all query and form field parameters available from the HTTP request. With RESTXQ, this function can be used to access parameters that have not been statically bound by %rest:query-param . |
---|
Errors | |
---|
Examples | For the example given in the introduction, this function would return name . |
---|
Signature | request:parameter(
$name as xs:string,
$default as xs:string := ()
) as xs:string* |
---|
Summary | Returns the value of the named query or form field parameter in an HTTP request. If the parameter does not exist, an empty sequence or the optionally specified default value is returned instead. If both query and form field parameters with the same name exist, the form field values will be attached to the query values. |
---|
Errors | |
---|
Examples | For the example given in the introduction, the function call request:parameter('code') would return 7 . |
---|
Added: New function.
Signature | request:header-map() as map(xs:string, xs:string*) |
---|
Summary | Returns all headers available from the HTTP request. If RESTXQ is used, this function can be used to access headers that have not been statically bound by %rest:header-param . |
---|
Signature | request:header-names() as xs:string* |
---|
Summary | Returns the names of all headers available from the HTTP request. If RESTXQ is used, this function can be used to access headers that have not been statically bound by %rest:header-param . |
---|
Signature | request:header(
$name as xs:string,
$default as xs:string := ()
) as xs:string* |
---|
Summary | Returns the values of the named header in an HTTP request. The header search is case insensitive. If the header does not exist, an empty sequence or the optionally specified default value is returned instead. |
---|
Added: New function.
Signature | request:cookie-map() as map(xs:string, xs:string) |
---|
Summary | Returns all cookies in the HTTP headers available from the HTTP request. If RESTXQ is used, this function can be used to access cookies that have not been statically bound by %rest:cookie-param . |
---|
Signature | request:cookie-names() as xs:string* |
---|
Summary | Returns the names of all cookies in the HTTP headers available from the HTTP request. If RESTXQ is used, this function can be used to access cookies that have not been statically bound by %rest:cookie-param . |
---|
Signature | request:cookie(
$name as xs:string,
$default as xs:string := ()
) as xs:string? |
---|
Summary | Returns the value of the named Cookie in an HTTP request. If there is no such cookie, an empty sequence or the optionally specified default value is returned instead. |
---|
Added: New function.
Signature | request:attribute-map() as map(xs:string, item()*) |
---|
Summary | Returns all HTTP request attributes. If a value is not an XDM item value, it is wrapped as a Java item. |
---|
Signature | request:attribute-names() as xs:string* |
---|
Summary | Returns the names of all HTTP request attributes. |
---|
Signature | request:attribute(
$name as xs:string,
$default as item()* := ()
) as item()* |
---|
Summary | Returns the value of an attribute of the HTTP request. If the value is not an XDM item value, it is wrapped as a Java item. If the attribute does not exist, an empty sequence or the optionally specified default value is returned instead. |
---|
Examples | request:attribute("javax.servlet.error.request_uri") Returns the original URI of a caught error.
request:attribute("javax.servlet.error.message") Returns the error message of a caught error. |
---|
Signature | request:set-attribute(
$name as xs:string,
$value as item()*
) as empty-sequence() |
---|
Summary | Binds the specified $value to the request attribute with the specified $name . |
---|
Code | Description |
---|
parameter | Request has invalid parameters. |
Version 12.0Version 9.3Version 7.9Version 7.8Version 7.7Version 7.5
⚡Generated with XQuery