=Getting started=
First of all, launch the BaseX as [[Web Application]]. By default, [http://jetty.codehaus.org/jetty/ Jetty] is used as web server. All HTTP services will be available on port <code>8984</code>, and the RESTXQ service is accessible at {{MonoCode|http://localhost:8984/restxq/}}. If the server is started as servlet, all [[Options#Main Options|Main Options]] (such as the path to the database) can be configured in the {{MonoCode|web.xml}} file. If run as a standalone application, the settings are stored in the file {{MonoCode|.basex}}.
=Module Declarations=
A RESTXQ module needs to contain a declaration to the namespace {{MonoCode|http://exquery.org/ns/restxq}}. A ''Resource Function'' is an XQuery function that has been marked up with RESTXQ annotations (annotations will be introduced with the upcoming [[XQuery 3.0]] standard). When an HTTP request comes in, a resource function will be invoked that matches the constraints indicated by its annotations.
All files with extension {{MonoCode|*.xqm}}, placed inside the directory specified by {{MonoCode|HTTPPATH}} (refer to [[Web Application#Configuring Database Access|HTTP Server Configuration]]) will be treated as RESTXQ modules. These will be parsed for RESTXQ annotations and cached. If a module is modified, it will be parsed again at runtime.
A simple RESTXQ module is shown below, it is part of a clean installation and available at http://localhost:8984/restxq/ .
Two additional annotations can be used to restrict functions to specific content types:
* '''HTTP Content Types''': a function will only be invoked if the HTTP {{MonoCode|Content-Type}} header of the request matches one of the given mime types. Example:
<pre class="brush:xquery">%rest:consumes("application/xml", "text/xml")</pre>
* '''HTTP Accept''': a function will only be invoked if the HTTP {{MonoCode|Accept}} header of the request matches one of the defined mime types. Example:
<pre class="brush:xquery">%rest:produces("application/atom+xml")</pre>
By default, both mime types are {{MonoCode|*/*}}.
==Parameters==
==Output==
By default, all results will be returned with content type {{MonoCode|application/xml}}.
Similar to our [[REST#Content Type|REST]] interface, result serialization can be modified via [[XQuery 3.0#Serialization|XQuery 3.0 serialization parameters]]. In RESTXQ, all parameters are specified within annotations.
The content type can be overwritten with the {{MonoCode|media-type}} annotation:
<pre class="brush:xquery">
</pre>
Next, the content type can also be overwritten by specifying an output {{MonoCode|method}}. The following method mappings are available:
* <code>xml</code> → <code>application/xml</code>
* <code>json</code> or <code>jsonml</code> → <code>application/json</code>
The following example will use {{MonoCode|text/html}} as content type:
<pre class="brush:xquery">