Difference between revisions of "Request Module"
Jump to navigation
Jump to search
m (Text replacement - "'''Signatures'''" to "'''Signature'''") |
|||
Line 24: | Line 24: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:method() as xs:string</pre> | |<pre>request:method() as xs:string</pre> | ||
|- valign="top" | |- valign="top" | ||
Line 36: | Line 36: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:scheme() as xs:string</pre> | |<pre>request:scheme() as xs:string</pre> | ||
|- valign="top" | |- valign="top" | ||
Line 49: | Line 49: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:hostname() as xs:string</pre> | |<pre>request:hostname() as xs:string</pre> | ||
|- valign="top" | |- valign="top" | ||
Line 62: | Line 62: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:port() as xs:integer</pre> | |<pre>request:port() as xs:integer</pre> | ||
|- valign="top" | |- valign="top" | ||
Line 75: | Line 75: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:path() as xs:string</pre> | |<pre>request:path() as xs:string</pre> | ||
|- valign="top" | |- valign="top" | ||
Line 88: | Line 88: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:query() as xs:string?</pre> | |<pre>request:query() as xs:string?</pre> | ||
|- valign="top" | |- valign="top" | ||
Line 101: | Line 101: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:uri() as xs:anyURI</pre> | |<pre>request:uri() as xs:anyURI</pre> | ||
|- valign="top" | |- valign="top" | ||
Line 115: | Line 115: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:context-path() as xs:string</pre> | |<pre>request:context-path() as xs:string</pre> | ||
|- valign="top" | |- valign="top" | ||
Line 127: | Line 127: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:address() as xs:string</pre> | |<pre>request:address() as xs:string</pre> | ||
|- valign="top" | |- valign="top" | ||
Line 137: | Line 137: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:remote-hostname() as xs:string</pre> | |<pre>request:remote-hostname() as xs:string</pre> | ||
|- valign="top" | |- valign="top" | ||
Line 147: | Line 147: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:remote-address() as xs:string</pre> | |<pre>request:remote-address() as xs:string</pre> | ||
|- valign="top" | |- valign="top" | ||
Line 157: | Line 157: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:remote-port() as xs:string</pre> | |<pre>request:remote-port() as xs:string</pre> | ||
|- valign="top" | |- valign="top" | ||
Line 170: | Line 170: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:parameter-names() as xs:string*</pre> | |<pre>request:parameter-names() as xs:string*</pre> | ||
|- valign="top" | |- valign="top" | ||
Line 187: | Line 187: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:parameter( | |<pre>request:parameter( | ||
$name as xs:string | $name as xs:string | ||
Line 208: | Line 208: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:header-names() as xs:string*</pre> | |<pre>request:header-names() as xs:string*</pre> | ||
|- valign="top" | |- valign="top" | ||
Line 218: | Line 218: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:header( | |<pre>request:header( | ||
$name as xs:string | $name as xs:string | ||
Line 233: | Line 233: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:cookie-names() as xs:string*</pre> | |<pre>request:cookie-names() as xs:string*</pre> | ||
|- valign="top" | |- valign="top" | ||
Line 243: | Line 243: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:cookie( | |<pre>request:cookie( | ||
$name as xs:string | $name as xs:string | ||
Line 259: | Line 259: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:attribute-names() as xs:string*</pre> | |<pre>request:attribute-names() as xs:string*</pre> | ||
|- valign="top" | |- valign="top" | ||
Line 270: | Line 270: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:attribute( | |<pre>request:attribute( | ||
$name as xs:string | $name as xs:string | ||
Line 289: | Line 289: | ||
{| width='100%' | {| width='100%' | ||
|- valign="top" | |- valign="top" | ||
− | | width='120' | ''' | + | | width='120' | '''Signature''' |
|<pre>request:set-attribute( | |<pre>request:set-attribute( | ||
$name as xs:string | $name as xs:string |
Revision as of 15:04, 9 March 2023
This XQuery 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.
Contents
Conventions
- 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 therequest
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
General Functions
request:method
Signature | request:method() as xs:string |
Summary | Returns the Method of the HTTP request. |
URI Functions
request:scheme
Signature | request:scheme() as xs:string |
Summary | Returns the Scheme component of the URI of an HTTP request. |
Example | For the example given in the introduction, this function would return foo .
|
request:hostname
Signature | request:hostname() as xs:string |
Summary | Returns the Hostname component of the URI of an HTTP request. |
Example | For the example given in the introduction, this function would return example.com .
|
request:port
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. |
Example | For the example given in the introduction, this function would return 8042 .
|
request:path
Signature | request:path() as xs:string |
Summary | Returns the Path component of the URI of an HTTP request. |
Example | For the example given in the introduction, this function would return /over/there . |
request:query
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. |
Example | For the example given in the introduction, this function would return name=ferret&code=7 . |
request:uri
Signature | request:uri() as xs:anyURI |
Summary | Returns the complete URI of an HTTP request as it has been specified by the client. |
Example | For the example given in the introduction, this method would return foo://example.com:8042/over/there?name=ferret&code=7 . |
request:context-path
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. |
Connection Functions
request:address
Signature | request:address() as xs:string |
Summary | Returns the IP address of the server. |
request:remote-hostname
Signature | request:remote-hostname() as xs:string |
Summary | Returns the fully qualified hostname of the client that sent the request. |
request:remote-address
Signature | request:remote-address() as xs:string |
Summary | Returns the IP address of the client that sent the request. |
request:remote-port
Signature | request:remote-port() as xs:string |
Summary | Returns the TCP port of the client socket that triggered the request. |
Parameter Functions
request:parameter-names
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. |
Example | For the example given in the introduction, this function would return name . |
Errors | parameter : the request has invalid parameters.
|
request:parameter
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. |
Example | For the example given in the introduction, the function call request:parameter('code') would return 7 . |
Errors | parameter : the request has invalid parameters.
|
Header Functions
request:header-names
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. |
request:header
Signature | request:header( $name as xs:string $default as xs:string := () ) as xs:string? |
Summary | Returns the value of the named header in an HTTP request. If the header does not exist, an empty sequence or the optionally specified default value is returned instead. |
Cookie Functions
request:cookie-names
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. |
request:cookie
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. |
Attribute Functions
request:attribute-names
Signature | request:attribute-names() as xs:string* |
Summary | Returns the names of all HTTP request attributes. |
request:attribute
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 attribute does not exist, an empty sequence or the optionally specified default value is returned instead. |
Example |
|
request:set-attribute
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 .
|
Errors
Code | Description |
---|---|
parameter
|
Request has invalid parameters. |
Changelog
- Version 9.3
- Added:
request:attribute-names
,request:set-attribute
- Updated:
request:attribute
: return type generalized, default argument added
- Version 7.9
- Updated: The returned values of
request:parameter-names
,request:parameter
now also include form field parameters.
- Version 7.8
- Added:
request:context-path
- Version 7.7
- Added:
request:attribute
This module was introduced with Version 7.5.