Changes

Jump to navigation Jump to search
2,685 bytes added ,  23:37, 8 September 2012
Created page with "This XQuery Module contains functions for handling session information on an HTTP request that has triggered the query. This module is mainly useful in the con..."
This [[Module Library|XQuery Module]] contains functions for handling session information on an HTTP request that has triggered the query. This module is mainly useful in the context of [[Web Application]]s.

=Conventions=

All functions in this module are assigned to the {{Code|http://basex.org/modules/session}} namespace, which must be dynamically imported. In this documentation, the namespace is bound to the {{Code|session}} prefix.

=Functions=

==session:id==
{|
|-
| width='90' | '''Signatures'''
|{{Func|request:session-id||xs:string}}
|-
| '''Summary'''
|Returns the session ID of a servlet request.
|-
| '''Examples'''
|The following RESTXQ function can be called via <code><nowiki>http://localhost:8984/restxq/id</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("/id")
function test:id()
{
'ID: ' || request:session-id()
};
</pre>
|}

==session:attribute==
{|
|-
| width='90' | '''Signatures'''
|{{Func|request:attribute|$key as xs:string|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 <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")
%restxq:query-param("key", "{$key}", "")
%restxq:request("{$req}")
function test:get($req, $key)
{
'Value of ' || $key || ': ' || request:get-attribute($req, $key)
};
</pre>
|}

==session:update-attribute==
{|
|-
| width='90' | '''Signatures'''
|{{Func|request:update-attribute|$key as xs:string, $value as xs:string|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 <code><nowiki>http://localhost:8984/restxq/set?key=user&value=john</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("/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.'
};
</pre>
|}

=Changelog=

This module was introduced with Version 7.5.

[[Category:XQuery]]
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu