Changes

Jump to navigation Jump to search
1,291 bytes added ,  06:53, 29 November 2019
This [[Module Library|XQuery Module]] contains functions for retrieving information on an HTTP request that has triggered the query. It is mainly mostly useful in the context of when building [[Web Application]]s.
The module is related to Adam Retter’s based on the [http://exquery.github.com/expath-specs-playground/request-module-1.0-specification.html EXQuery Request Module] draft.
=Conventions=
* The module will be available if the {{Code|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 <code><nowiki>http://exquery.org/ns/request</nowiki></code> namespace. The module must be imported in the query prolog:<pre class="brush:xquery">import module namespace request = "http://exquery.org/ns/request";...</pre>* In this document, the namespace which is statically bound to the {{Code|request}} prefix.
* If any of the functions is called outside the servlet context, <code>[[XQuery Errors#BaseX Errors|basex:http]]</code> is raised.
| '''Summary'''
|Returns the Method of the HTTP request.
|}
 
==request:attribute==
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|request:attribute|$name as xs:string|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'''
|
* {{Code|request:attribute("javax.servlet.error.request_uri")}} returns the original URI of a caught error.
* {{Code|request:attribute("javax.servlet.error.message")}} returns the error message of a caught error.
|}
|-
| '''Summary'''
|Returns the Query component of the URI of an HTTP request. If no query has been specifiedcomponent exists, an empty sequence is returned.
|-
| '''Example'''
| '''Example'''
|For the example given in the introduction, this function would return {{Code|name}}.<br/>
|-
| '''Errors'''
|{{Error|parameter|#Errors}} the request has invalid parameters.
|}
| '''Example'''
|For the example given in the introduction, the function call {{Code|request:parameter('name')}} would return {{Code|ferret}}.<br/>
|-
| '''Errors'''
|{{Error|parameter|#Errors}} the request has invalid parameters.
|}
|-
| width='120' | '''Signatures'''
|{{Func|request:cookie|$name as xs:string|xs:string*?}}<br/>{{Func|request:cookie|$name as xs:string, $default as xs:string|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==
 
{{Mark|Introduced with BaseX 9.3:}}
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|request:attribute-names||xs:string*}}
|-
| '''Summary'''
|Returns the names of all HTTP request attributes.
|}
 
==request:attribute==
 
{{Mark|Updated with BaseX 9.3:}} return type generalized, default argument added.
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|request:attribute|$name as xs:string|item()*}}<br/>{{Func|request:attribute|$name as xs:string, $default as item()*|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'''
|
* {{Code|request:attribute("javax.servlet.error.request_uri")}} returns the original URI of a caught error.
* {{Code|request:attribute("javax.servlet.error.message")}} returns the error message of a caught error.
|}
 
==request:set-attribute==
 
{{Mark|Introduced with BaseX 9.3:}}
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|request:set-attribute|$name as xs:string, $value as item()*|empty-sequence()}}
|-
| '''Summary'''
|Binds the specified {{Code|$value}} to the request attribute with the specified {{Code|$name}}.
|-
| '''Errors'''
|{{Error|attribute|#Errors}} The supplied value cannot be materialized.
|}
 
=Errors=
 
{| class="wikitable" width="100%"
! width="110"|Code
|Description
|-
|{{Code|attribute}}
|An attribute cannot be retrieved or stored.
|-
|{{Code|parameter}}
|Request has invalid parameters.
|}
=Changelog=
 
;Version 9.3
 
* Added: [[#request:attribute-names|request:attribute-names]], [[#request:set-attribute|request:set-attribute]]
* Updated: [[#request:attribute|request:attribute]]: return type generalized, default argument added
;Version 7.9
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu