Difference between revisions of "Session Module"

From BaseX Documentation
Jump to navigation Jump to search
Line 1: Line 1:
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.
+
This [[Module Library|XQuery Module]] contains functions for accessing and modifying server-side session information. This module is mainly useful in the context of [[Web Application]]s.
  
 
=Conventions=
 
=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.
+
As sessions are side-effecting operations, all functions in this module are flagged as ''non-deterministic''. This means that the evaluation order of the functions will not be influenced by the compiler.
 +
 
 +
All functions 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. Errors are assigned to the {{Code|http://basex.org/errors}} namespace, which is statically bound to the {{Code|bxerr}} prefix.
  
 
=Functions=
 
=Functions=
Line 72: Line 74:
 
| '''Summary'''
 
| '''Summary'''
 
|Assigns a value to a session attribute.
 
|Assigns a value to a session attribute.
|-
 
| '''Properties'''
 
|The function is ''non-deterministic'': evaluation order will be preserved by the compiler.
 
 
|-
 
|-
 
| '''Errors'''
 
| '''Errors'''
Line 95: Line 94:
 
| '''Summary'''
 
| '''Summary'''
 
|Deletes a session attribute.
 
|Deletes a session attribute.
|-
 
| '''Properties'''
 
|The function is ''non-deterministic'': evaluation order will be preserved by the compiler.
 
 
|-
 
|-
 
| '''Errors'''
 
| '''Errors'''

Revision as of 06:10, 9 September 2012

This XQuery Module contains functions for accessing and modifying server-side session information. This module is mainly useful in the context of Web Applications.

Conventions

As sessions are side-effecting operations, all functions in this module are flagged as non-deterministic. This means that the evaluation order of the functions will not be influenced by the compiler.

All functions 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. Errors are assigned to the http://basex.org/errors namespace, which is statically bound to the bxerr prefix.

Functions

session:id

Signatures session:id() as xs:string
Summary Returns the session ID of a servlet request.
Examples Running a RESTXQ function 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() {
  'Session ID: ' || session:id()
};

session:attribute-names

Signatures session:attribute-names() as xs:string*
Summary Returns the names of all attributes bound to the current session.
Examples Running the server-side XQuery file attributes.xq via http://localhost:8984/attributes.xq:
import module namespace session = "http://basex.org/modules/session";
session:attributes() ! element attribute { . }

session:attribute

Signatures session:attribute($key as xs:string) as xs:string?
session:attribute($key as xs:string, $default as xs:string) as xs:string
Summary Returns the value of an attribute bound to the current session. If the attribute does not exist, an empty sequence or the optionally specified default value is returned instead.
Errors BXSE0002: the value of a session attribute could not be retrieved.
Examples Running the server-side XQuery file get.xq via http://localhost:8984/get.xq?key=user:
import module namespace session = "http://basex.org/modules/session";
'Value of ' || $key || ': ' || session:attribute($key)

session:update-attribute

Signatures session:update-attribute($key as xs:string, $value as xs:string) as empty-sequence()
Summary Assigns a value to a session attribute.
Errors BXSE0001: a function item was specified as value of a session attribute.
Examples Running the server-side XQuery file set.xq via http://localhost:8984/set.xq?key=user&value=john:
import module namespace session = "http://basex.org/modules/session";
session:update-attribute($key, $value), 'Attribute was set.'

session:delete-attribute

Signatures session:delete-attribute($key as xs:string) as empty-sequence()
Summary Deletes a session attribute.
Errors BXSE0001: a function item was specified as value of a session attribute.
Examples Running the server-side XQuery file delete.xq via http://localhost:8984/delete.xq?key=user:
import module namespace session = "http://basex.org/modules/session";
session:delete-attribute($key), 'Attribute was deleted.'

session:close

Signatures session:close() as empty-sequence()
Summary Invalidates a session.

Errors

Code Description
BXSE0001 A function item was specified as value of a session attribute.
BXSE0002 An error occurred while retrieving the value of a session attribute.

Changelog

This module was introduced with Version 7.5.