Difference between revisions of "Session Module"

From BaseX Documentation
Jump to navigation Jump to search
Line 11: Line 11:
 
|-
 
|-
 
| width='90' | '''Signatures'''
 
| width='90' | '''Signatures'''
|{{Func|request:id||xs:string}}
+
|{{Func|session:id||xs:string}}
 
|-
 
|-
 
| '''Summary'''
 
| '''Summary'''
Line 20: Line 20:
 
<pre class="brush:xquery">
 
<pre class="brush:xquery">
 
module namespace test = 'http://basex.org/examples/test';
 
module namespace test = 'http://basex.org/examples/test';
import module namespace request = "http://exquery.org/ns/restxq/request";
+
import module namespace session = "http://basex.org/modules/session";
 
declare
 
declare
 
   %restxq:path("/id")
 
   %restxq:path("/id")
 
   function test:id()
 
   function test:id()
 
{
 
{
   'ID: ' || request:session-id()
+
   'ID: ' || session:id()
 
};
 
};
 
</pre>
 
</pre>
Line 34: Line 34:
 
|-
 
|-
 
| width='90' | '''Signatures'''
 
| width='90' | '''Signatures'''
|{{Func|request:attribute|$key as xs:string|xs:string?}}
+
|{{Func|session:attribute|$key as xs:string|xs:string?}}
 
|-
 
|-
 
| '''Summary'''
 
| '''Summary'''
Line 43: Line 43:
 
<pre class="brush:xquery">
 
<pre class="brush:xquery">
 
module namespace test = 'http://basex.org/examples/test';
 
module namespace test = 'http://basex.org/examples/test';
import module namespace request = "http://exquery.org/ns/restxq/request";
+
import module namespace session = "http://basex.org/modules/session";
 
declare
 
declare
 
   %restxq:path("/get")
 
   %restxq:path("/get")
 
   %restxq:query-param("key", "{$key}", "")
 
   %restxq:query-param("key", "{$key}", "")
  %restxq:request("{$req}")
 
 
   function test:get($req, $key)
 
   function test:get($req, $key)
 
{
 
{
   'Value of ' || $key || ': ' || request:get-attribute($req, $key)
+
   'Value of ' || $key || ': ' || session:attribute($req, $key)
 
};
 
};
 
</pre>
 
</pre>
Line 59: Line 58:
 
|-
 
|-
 
| width='90' | '''Signatures'''
 
| width='90' | '''Signatures'''
|{{Func|request:update-attribute|$key as xs:string, $value as xs:string|empty-sequence()}}
+
|{{Func|session:update-attribute|$key as xs:string, $value as xs:string|empty-sequence()}}
 
|-
 
|-
 
| '''Summary'''
 
| '''Summary'''
Line 68: Line 67:
 
<pre class="brush:xquery">
 
<pre class="brush:xquery">
 
module namespace test = 'http://basex.org/examples/test';
 
module namespace test = 'http://basex.org/examples/test';
import module namespace request = "http://exquery.org/ns/restxq/request";
+
import module namespace session = "http://basex.org/modules/session";
 
declare
 
declare
 
   %restxq:path("/set")
 
   %restxq:path("/set")
 
   %restxq:query-param("key", "{$key}", "")
 
   %restxq:query-param("key", "{$key}", "")
 
   %restxq:query-param("value", "{$value}", "")
 
   %restxq:query-param("value", "{$value}", "")
  %restxq:request("{$req}")
 
 
   function test:set($req, $key, $value)
 
   function test:set($req, $key, $value)
 
{
 
{
   request:set-attribute($req, $key, $value),
+
   session:update-attribute($req, $key, $value),
 
   'Attribute was set.'
 
   'Attribute was set.'
 
};
 
};

Revision as of 00:16, 9 September 2012

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 context of Web Applications.

Conventions

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

Functions

session:id

Signatures 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 session = "http://basex.org/modules/session";
declare
  %restxq:path("/id")
  function test:id()
{
  'ID: ' || session:id()
};

session:attribute

Signatures session:attribute($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 session = "http://basex.org/modules/session";
declare
  %restxq:path("/get")
  %restxq:query-param("key", "{$key}", "")
  function test:get($req, $key)
{
  'Value of ' || $key || ': ' || session:attribute($req, $key)
};

session:update-attribute

Signatures session:update-attribute($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 session = "http://basex.org/modules/session";
declare
  %restxq:path("/set")
  %restxq:query-param("key", "{$key}", "")
  %restxq:query-param("value", "{$value}", "")
  function test:set($req, $key, $value)
{
  session:update-attribute($req, $key, $value),
  'Attribute was set.'
};

Changelog

This module was introduced with Version 7.5.