Request Module

From BaseX Documentation

Jump to: navigation, search

This XQuery Module contains functions for retrieving information on an HTTP request that has triggered the query. It is mainly useful in the context of Web Applications.

The module is related to Adam Retter’s EXQuery Request Module draft.

Contents

[edit] Conventions

import module namespace request = "http://exquery.org/ns/request";
...
  foo://example.com:8042/over/there?name=ferret
  \_/   \_________/ \__/\_________/ \_________/
   |         |       |       |          |
 scheme   hostname  port    path      query

[edit] General Functions

[edit] request:method

Signatures request:method() as xs:string
Summary Returns the Method of the HTTP request.

[edit] request:attribute

Signatures request:attribute($name as xs:string) as xs:string
Summary Returns the value of an attribute of the HTTP request. If the attribute does not exist, an empty sequence is returned.
Example
  • 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.

[edit] URI Functions

[edit] request:scheme

Signatures 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.

[edit] request:hostname

Signatures 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.

[edit] request:port

Signatures 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.

[edit] request:path

Signatures 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.

[edit] request:query

Signatures request:query() as xs:string?
Summary Returns the Query component of the URI of an HTTP request. If no query has been specified, an empty sequence is returned.
Example For the example given in the introduction, this function would return name=ferret.

[edit] request:uri

Signatures 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.

[edit] request:context-path

Signatures 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.

[edit] Connection Functions

[edit] request:address

Signatures request:address() as xs:string
Summary Returns the IP address of the server.

[edit] request:remote-hostname

Signatures request:remote-hostname() as xs:string
Summary Returns the fully qualified hostname of the client that sent the request.

[edit] request:remote-address

Signatures request:remote-address() as xs:string
Summary Returns the IP address of the client that sent the request.

[edit] request:remote-port

Signatures request:remote-port() as xs:string
Summary Returns the TCP port of the client socket that triggered the request.

[edit] Parameter Functions

[edit] request:parameter-names

Signatures 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.

[edit] request:parameter

Signatures request:parameter($name as xs:string) as xs:string*
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('name') would return ferret.

[edit] Header Functions

[edit] request:header-names

Signatures 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.

[edit] request:header

Signatures request:header($name as xs:string) as xs:string?
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.

[edit] Cookie Functions

[edit] request:cookie-names

Signatures 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.

[edit] request:cookie

Signatures request:cookie($name as xs:string) as xs:string*
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.

[edit] Changelog

Version 7.9
Version 7.8
Version 7.7

This module was introduced with Version 7.5.

Personal tools
Namespaces
Variants
Actions
Navigation
Print/export