dba/common
library moduleRA
Summary
Common RESTXQ access points.
- Tags
Author: Christian Grün, BaseX Team 2005-21, BSD License
__source : common.xqm
Imports
This module is imported by 0 modules. It imports 1 modules.
Variables
None
Functions
4.1 dba:file
Arities: dba:file#1RA
dba:file
(
$file
as
xs:string
)
as
item() +
- file
as
xs:string
file or unknown path
item() +
rest binary data
Invoked by 0 functions from 0 modules
Annotations
%rest:path | ('/dba/static/{$file=.+}') |
%output:method | ('basex') |
%perm:allow | ('public') |
Source ( 0 lines)
4.2 dba:redirect
Arities: dba:redirect#0R
dba:redirect
(
)
as
element(rest:response)
element(rest:response)
redirection
Invoked by 0 functions from 0 modules
Annotations
%rest:path | ('/dba') |
Source ( 0 lines)
4.3 dba:unknown
Arities: dba:unknown#1RA
dba:unknown
(
$path
as
xs:string
)
as
element(html)
- path
as
xs:string
path to unknown page
element(html)
page
Invoked by 0 functions from 0 modules
Annotations
%rest:path | ('/dba/{$path}') |
%output:method | ('html') |
Source ( 0 lines)
Namespaces
The following namespaces are defined:
Prefix | Uri |
---|---|
dba | dba/common |
html | dba/html |
output | http://www.w3.org/2010/xslt-xquery-serialization |
perm | http://basex.org/modules/perm |
rest | http://exquery.org/ns/restxq |
6 RestXQ
Paths defined 3.
Path | Method | Function |
---|---|---|
/dba | dba:redirect#0 | |
/dba/static/{$file=.+} | dba:file#1 | |
/dba/{$path} | dba:unknown#1 |
Source Code
(:~
: Common RESTXQ access points.
:
: @author Christian Grün, BaseX Team 2005-21, BSD License
:)
module namespace dba = 'dba/common';
import module namespace html = 'dba/html' at 'lib/html.xqm';
(:~
: Redirects to the start page.
: @return redirection
:)
declare
%rest:path('/dba')
function dba:redirect(
) as element(rest:response) {
web:redirect('/dba/logs')
};
(:~
: Returns a file.
: @param $file file or unknown path
: @return rest binary data
:)
declare
%rest:path('/dba/static/{$file=.+}')
%output:method('basex')
%perm:allow('public')
function dba:file(
$file as xs:string
) as item()+ {
let $path := file:base-dir() || 'static/' || $file
return (
web:response-header(
map { 'media-type': web:content-type($path) },
map { 'Cache-Control': 'max-age=3600,public', 'Content-Length': file:size($path) }
),
file:read-binary($path)
)
};
(:~
: Shows a 'page not found' error.
: @param $path path to unknown page
: @return page
:)
declare
%rest:path('/dba/{$path}')
%output:method('html')
function dba:unknown(
$path as xs:string
) as element(html) {
html:wrap(
<tr>
<td>
<h2>Page not found:</h2>
<ul>
<li>Page: dba/{ $path }</li>
<li>Method: { request:method() }</li>
</ul>
</td>
</tr>
)
};