Changes

Jump to navigation Jump to search
1,236 bytes added ,  12:54, 22 March 2012
→‎Module Declarations: section refers to a preinstalled restxq.xqm module
All files with extension {{Mono|*.xqm}}, placed inside the {{Mono|HTTPPATH}} (refer to [[BaseX Web Application|HTTP Server Configuration]]) will be treated as RESTXQ modules. These will searched for matching RESTXQ annotations on each HTTP request.
A simple RESTXQ module is shown below, it is part of a clean installation and avaliable at http://localhost:8984/restxq/ .
<pre class="brush:xquery">(:~ A simple simplified module with REST-annotations as in http/restxq.xqm :)module namespace hw page = 'http://basex.org/modules/web-page';declare namespace rest = 'http://exquery.org/ns/restxq'; declare %rest:path("hello/{$world}") %rest:GET %rest:header-demo'param("User-Agent", "{$agent}")function page:hello($world as xs:string, $agent as xs:string) { <response> <title>Hello { $world }!</title> <info>You requested this page with { $agent }.</info> </response>};</pre> If the URI http://localhost:8984/restxq/hello/world is accessed, the result will be kind of
declare namespace rest <pre class= 'http"brush:xml">&lt;response> &lt;title>Hello world!&lt;/title> &lt;info>You requested this page with Mozilla/exquery5.0 (Windows; U; Windows NT 5.org1; en-US) AppleWebKit/ns525.13 (KHTML, like Gecko) Chrome/restxq'0.2.149.27 Safari/525.13.&lt;/info>&lt;/response></pre>
declare %restWe added another method within that module:path("{$path}") %output:media-type("application/xml")function hw:demo($path as xs:string) { &lt;xml&gt; Hello World! You accessed the path { $path }. &lt;/xml&gt;};</pre>
If the URI <pre class="brush:xml">declare %rest:path("hello/{$world}") %rest:POST %rest:form-param("content","{Mono|http$post-content}") function page://localhosthello-postman($world as xs:8984string, $post-content as document-node()) { &lt;response> &lt;title>Hello { $world }!&lt;/restxq/demotitle> &lt;info>It seems you posted a message { $post-modulecontent }.&lt;/info> &lt;/response>} is accessed, the result will be;</pre>
If you posted something (e.g. using curl or the embedded formular http://localhost:8984/restxq/ )<pre class="brush:shell">curl -i -X POST -H "content-type: application/xml" -d 'content="Here comes the post!"' 'http://admin:admin@localhost:8984/restxq/hello/mr-postman'</pre>You would recieve<pre class="brush:xml">&lt;response> &lt;xmltitle>Hello mr-postman!&gtlt;/title> Hello World&lt;info>It seems you posted a message "Here comes the post! You accessed the path demo-module".&lt;/xmlinfo>&gtlt;/response></pre>
=Annotations=
editor, reviewer
115

edits

Navigation menu