Changes

Jump to navigation Jump to search
115 bytes removed ,  18:39, 1 December 2023
m
Text replacement - "syntaxhighlight" to "pre"
| width='120' | '''Signature'''
|<pre>web:create-url(
$url href as xs:string, $parameters as map(*),
$anchor as xs:string := ()
) as xs:string</pre>
|- valign="top"
| '''Summary'''
|Creates a new URL from the specified <code>{{Code|$url</code> href}} string, query string <code>$parameters</code> and an optional {{Code|$anchor}} reference. The keys and values of the map entries will be converted to strings, URL-encoded (see {{Function||web:encode-url}}), and appended to the URL as query parameters. If a map entry has more than a single item, all of them will be appended as single parameters.
|- valign="top"
| '''Examples'''
| width='120' | '''Signature'''
|<pre>web:forward(
$path as xs:string,
$parameters as map(*) := ()
) as element(rest:forward)</pre>
|
The function call <code><nowiki>web:forward('/a/b')</nowiki></code> creates the following result (which will be interpreted as forwarding if RESTXQ is used):
<syntaxhighlight pre lang="xml">
<rest:forward>/a/b</rest:forward>
</syntaxhighlightpre>
|}
| width='120' | '''Signature'''
|<pre>web:redirect(
$url as xs:string, $parameters as map(*) := (),
$anchor as xs:string := ()
) as element(rest:response)</pre>
|
The query <code><nowiki>web:redirect('/a/b')</nowiki></code> returns the following result (which will be interpreted as redirection if RESTXQ is used):
<syntaxhighlight pre lang="xml">
<rest:response xmlns:rest="http://exquery.org/ns/restxq">
<http:response xmlns:http="http://expath.org/ns/http-client" status="302">
</http:response>
</rest:response>
</syntaxhighlightpre>
|}
| width='120' | '''Signature'''
|<pre>web:response-header(
$output as map(*)? := (), $headers as map(*)? := (),
$atts as map(*)? := ()
) as element(rest:response)</pre>
|
* The function call <code>web:response-header()</code> returns:
<syntaxhighlight pre lang="xml">
<rest:response xmlns:rest="http://exquery.org/ns/restxq">
<http:response xmlns:http="http://expath.org/ns/http-client"/>
<output:serialization-parameters xmlns:output="http://www.w3.org/2010/xslt-xquery-serialization"/>
</rest:response>
</syntaxhighlightpre>
* The following expression returns a media-type for binary data, a caching directive, and the OK status:<br/>
<syntaxhighlight pre lang="'xquery"'>
web:response-header(
map { 'media-type': 'application/octet-stream' },
map { 'status': 200, 'message': 'OK' }
)
</syntaxhighlightpre>
* The following RESTXQ function returns the contents of a file to the client with correct media type:<br/>
<syntaxhighlight pre lang="'xquery"'>
declare %rest:path('media/{$file}') function local:get($file) {
let $path := 'path/to/' || $file
)
};
</syntaxhighlightpre>
|}
| width='120' | '''Signature'''
|<pre>web:error(
$status as xs:integer,
$message as xs:string
) as none</pre>
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu