Difference between revisions of "Request Module"

From BaseX Documentation
Jump to navigation Jump to search
Line 3: Line 3:
 
=Conventions=
 
=Conventions=
  
All functions in this module are assigned to the {{Code|http://exquery.org/ns/restxq/Request}} namespace, which must be dynamically imported. In this documentation, the {{Code|request}} prefix is used. Next, the first argument of all functions must be a servlet request container, bound via the <code>[[RESTXQ#Context|%restxq:request(...)]]</code> annotation. An example:
+
All functions in this module are assigned to the {{Code|http://exquery.org/ns/restxq/request}} namespace, which must be dynamically imported. In this documentation, the namespace is bound to the {{Code|request}} prefix.
 
 
<pre class='brush:xquery'>
 
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)
 
{
 
  ...
 
};
 
</pre>
 
  
 
=Functions=
 
=Functions=
Line 86: Line 71:
 
|-
 
|-
 
| width='90' | '''Signatures'''
 
| width='90' | '''Signatures'''
|{{Func|request:attribute|$request as basex:request, $key as xs:string|xs:string?}}
+
|{{Func|request:attribute|$key as xs:string|xs:string?}}
 
|-
 
|-
 
| '''Summary'''
 
| '''Summary'''
Line 112: Line 97:
 
|-
 
|-
 
| width='90' | '''Signatures'''
 
| width='90' | '''Signatures'''
|{{Func|request:update-attribute|$request as basex:request, $key as xs:string, $value as xs:string|empty-sequence()}}
+
|{{Func|request:update-attribute|$key as xs:string, $value as xs:string|empty-sequence()}}
 
|-
 
|-
 
| '''Summary'''
 
| '''Summary'''
Line 140: Line 125:
 
|-
 
|-
 
| width='90' | '''Signatures'''
 
| width='90' | '''Signatures'''
|{{Func|request:path|$request as basex:request|xs:string}}
+
|{{Func|request:path||xs:string}}
 
|-
 
|-
 
| '''Summary'''
 
| '''Summary'''

Revision as of 23:33, 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.

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 namespace is bound to the request prefix.

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($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($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() 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.