Changes

Jump to navigation Jump to search
2,140 bytes removed ,  00:06, 9 September 2012
no edit summary
|-
| '''Example'''
|For the example given in the introduction, this method function would return {{Code|foo}}.
|}
| '''Summary'''
|Returns the Hostname component of the URI of an HTTP request.
|-
| '''Example'''
|For the example given in the introduction, this function would return {{Code|example.com}}.
|}
| '''Summary'''
|Returns the Port component of the URI of an HTTP request, or a default port if it has not been explicitly specified in the URI.
|-
| '''Example'''
|For the example given in the introduction, this function would return {{Code|8042}}.
|}
|Returns the Path component of the URI of an HTTP request.
|-
| '''ExamplesExample'''|The following RESTXQ For the example given in the introduction, this function could e.g. be called via <code><nowiki>http:would return {{Code|/over/localhost:8984/restxq/path-check</nowiki></code>:<pre class="brush:xquery">module namespace test = 'http://basexthere}}.org/examples/test';import module namespace request = "http://exquery.org/ns/restxq/request";declare %restxq:path("/path-check") function test:get($req, $name) { 'Path of this page: ' || request:path()};<br/pre>
|}
| '''Summary'''
|Returns the Query component of the URI of an HTTP request. If no query has been specified, an empty sequence is returned.
|-
| '''Example'''
|For the example given in the introduction, this function would return {{Code|name=ferret}}.<br/>
|}
| '''Summary'''
|Returns the complete URI of an HTTP request as it has been specified by the client.
|-
| '''Example'''
|For the example given in the introduction, this method would return {{Code|foo://example.com:8042/over/there?name=ferret}}.<br/>
|}
| '''Summary'''
|Returns the names of all query parameters available from the HTTP request. This function can be used to find or check query parameters that have not been bound by [[RESTXQ#Query Strings|%restxq:query-param]] annotations.
|-
| '''Example'''
|For the example given in the introduction, this function would return {{Code|name}}.<br/>
|}
|Returns the value of the named query parameter in an HTTP request. If the parameter does not exist, an empty sequence or the optionally specified default value is returned instead.
|-
| '''ExamplesExample'''|The following RESTXQ For the example given in the introduction, the function can e.g. be called via <code><nowiki>http://localhost:8984/restxq/get?user=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("/get") function test:get() call {{ 'The user name is ' |Code| request:parameter('username')};} would return {{Code|ferret}}.<br/>
</pre>
|}
<pre class="brush:xquery">
request:parameter('Host')
</pre>
|}
 
==request: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>
|}
 
==request: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>
|}
 
==request: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>
|}
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu