Difference between revisions of "Request Module"
Jump to navigation
Jump to search
Line 21: | Line 21: | ||
=Functions= | =Functions= | ||
+ | |||
+ | ==request:parameter-names== | ||
+ | |||
+ | {| | ||
+ | |- | ||
+ | | width='90' | '''Signatures''' | ||
+ | |{{Func|request:parameter-names||xs:string*}} | ||
+ | |- | ||
+ | | '''Summary''' | ||
+ | |Returns the names of all query parameters contained in the HTTP request. | ||
+ | |} | ||
+ | |||
+ | ==request:parameter== | ||
+ | |||
+ | {| | ||
+ | |- | ||
+ | | width='90' | '''Signatures''' | ||
+ | |{{Func|request:parameter|$name as xs:string|xs:string*}} | ||
+ | |- | ||
+ | | '''Summary''' | ||
+ | |Returns all strings bound to the query parameter specified by {{Code|$name}}. | ||
+ | |- | ||
+ | | '''Examples''' | ||
+ | |The following RESTXQ function can e.g. be called via <code><nowiki>http://localhost:8984/restxq/get?key=user</nowiki></code>: | ||
+ | <pre class="brush:xquery"> | ||
+ | module namespace test = 'http://basex.org/examples/test'; | ||
+ | import module namespace request = "http://exquery.org/ns/restxq/request"; | ||
+ | declare | ||
+ | %restxq:path("/get") | ||
+ | function test:get() | ||
+ | { | ||
+ | 'Value of parameter "key": ' || request:parameter('key') | ||
+ | }; | ||
+ | </pre> | ||
+ | |} | ||
==request:session-id== | ==request:session-id== | ||
Line 27: | Line 62: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | |{{Func|request:session-id| | + | |{{Func|request:session-id||xs:string}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
Line 39: | Line 74: | ||
declare | declare | ||
%restxq:path("/id") | %restxq:path("/id") | ||
− | + | function test:id() | |
− | function test:id( | ||
{ | { | ||
− | 'ID: ' || request:session-id( | + | 'ID: ' || request:session-id() |
}; | }; | ||
</pre> | </pre> |
Revision as of 23:32, 21 August 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:parameter-names
Signatures | request:parameter-names() as xs:string*
|
Summary | Returns the names of all query parameters contained in the HTTP request. |
request:parameter
Signatures | request:parameter($name as xs:string) as xs:string*
|
Summary | Returns all strings bound to the query parameter specified by $name .
|
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") function test:get() { 'Value of parameter "key": ' || request:parameter('key') }; |
request:session-id
Signatures | request:session-id() 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") function test:id() { 'ID: ' || request:session-id() }; |
request:attribute
Signatures | request: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) }; |
request:update-attribute
Signatures | request:update-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:path
Signatures | request:path($request as basex:request) as xs:string
|
Summary | Returns the path relative to the RESTXQ URI. |
Examples | The following RESTXQ function can e.g. be called via http://localhost:8984/restxq/hey/john :
module namespace test = 'http://basex.org/examples/test'; import module namespace request = "http://exquery.org/ns/restxq/Request"; declare %restxq:path("/hey/{$name}") %restxq:request("{$req}") function test:get($req, $name) { 'Hey ' || $name || '! Relative path of this page: ' || request:path($req) }; |
Changelog
This module was introduced with Version 7.4.