Difference between revisions of "Request Module"
Jump to navigation
Jump to search
m (Text replace - "7.3.1" to "7.4") |
|||
Line 103: | Line 103: | ||
=Changelog= | =Changelog= | ||
− | This module was introduced with Version 7. | + | This module was introduced with Version 7.4. |
[[Category:XQuery]] | [[Category:XQuery]] |
Revision as of 11:57, 20 July 2012
This XQuery Module contains functions for processing servlet request data with the RESTXQ API. Note that, for now, the proposed functions are specific to BaseX and are not described in the existing RESTXQ documentations.
Contents
Conventions
All functions in this module are assigned to the http://exquery.org/ns/restxq/Request
namespace, which must be dynamically imported. In this documentation, the request
prefix is used. Next, the first argument of all functions must be a servlet request container, bound via the %restxq:request(...)
annotation. An example:
module namespace test = 'http://basex.org/examples/test'; import module namespace request = "http://exquery.org/ns/restxq/Request"; declare %restxq:GET %restxq:path("...") %restxq:request("{$request}") function test:function($request) { ... };
Functions
request:session-id
Signatures | request:session-id($request as basex:request) as xs:string
|
Summary | Returns the session ID of a servlet request. |
Examples | The following RESTXQ function can be called via http://localhost:8984/restxq/id :
module namespace test = 'http://basex.org/examples/test'; import module namespace request = "http://exquery.org/ns/restxq/Request"; declare %restxq:path("/id") %restxq:request("{$req}") function test:id($req) { 'ID: ' || request:session-id($req) }; |
request:set-attribute
Signatures | request:set-attribute($request as basex:request, $key as xs:string, $value as xs:string) as empty-sequence()
|
Summary | Binds an attribute with the specified value to the current session. |
Examples | The following RESTXQ function can e.g. be called via http://localhost:8984/restxq/set?key=user&value=john :
module namespace test = 'http://basex.org/examples/test'; import module namespace request = "http://exquery.org/ns/restxq/Request"; declare %restxq:path("/set") %restxq:query-param("key", "{$key}", "") %restxq:query-param("value", "{$value}", "") %restxq:request("{$req}") function test:set($req, $key, $value) { request:set-attribute($req, $key, $value), 'Attribute was set.' }; |
request:get-attribute
Signatures | request:get-attribute($request as basex:request, $key as xs:string) as xs:string?
|
Summary | Returns the value of an attribute bound to the current session, or an empty sequence if no value was bound. |
Examples | The following RESTXQ function can e.g. be called via http://localhost:8984/restxq/get?key=user :
module namespace test = 'http://basex.org/examples/test'; import module namespace request = "http://exquery.org/ns/restxq/Request"; declare %restxq:path("/get") %restxq:query-param("key", "{$key}", "") %restxq:request("{$req}") function test:get($req, $key) { 'Value of ' || $key || ': ' || request:get-attribute($req, $key) }; |
Changelog
This module was introduced with Version 7.4.