Changes

Jump to navigation Jump to search
200 bytes added ,  14:02, 27 February 2020
no edit summary
:<code>http://localhost:8984/rest</code>
<pre classsyntaxhighlight lang="brush:xml">
<rest:databases resources="1" xmlns:rest="http://basex.org/rest">
<rest:database resources="1" size="1813599">factbook</rest:database>
</rest:databases>
</presyntaxhighlight>
The resources of a database can be listed by specifying the database, and potential sub directories, in the URL.
:<code>http://localhost:8984/rest/factbook</code>
<pre classsyntaxhighlight lang="brush:xml">
<rest:database name="factbook" resources="1" xmlns:rest="http://basex.org/rest">
<rest:resource type="xml" content-type="application/xml" size="77192">factbook.xml</rest:resource>
</rest:database>
</presyntaxhighlight>
The contents of a database can be retrieved by directly addressing the resource:
* Create an empty database and return database information:
<pre classsyntaxhighlight lang="brush:xml">
<commands>
<create-db name='db'/>
<info-db/>
</commands>
</presyntaxhighlight>
For the other commands, the following child elements are supported:
* Return the first five city names of the <b>factbook</b> database:
<pre classsyntaxhighlight lang="brush:xml">
<rest:query xmlns:rest="http://basex.org/rest">
<rest:text><![CDATA[ (//city/name)[position() <= 5] ]]></rest:text>
</rest:query>
</presyntaxhighlight>
* Return string lengths of all text nodes that are found in the node that has been specified as initial context node:
<pre classsyntaxhighlight lang="brush:xml">
<query>
<text>for $i in .//text() return string-length($i)</text>
</context>
</query>
</presyntaxhighlight>
* Return the registered database users encoded in <code>ISO-8859-1</code>:
<pre classsyntaxhighlight lang="brush:xml">
<command>
<text>show users</text>
<parameter name='encoding' value='ISO-8859-1'/>
</command>
</presyntaxhighlight>
* Create a new database from the specified input and preserve all whitespaces:
<pre classsyntaxhighlight lang="brush:xml">
<command>
<text>create db test http://files.basex.org/xml/xmark.xml</text>
<option name='chop' value='false'/>
</command>
</presyntaxhighlight>
* Bind value to the {{Code|$person}} variable and run query <code>find-person.xq</code>, which must be located in the directory specified by {{Option|WEBPATH}}:
<pre classsyntaxhighlight lang="brush:xml">
<run>
<variable name='person' value='Johannes Müller'/>
<text>find-person.xq</text>
</run>
</presyntaxhighlight>
==PUT Method==
* The following request assigns two variables to a server-side query file <code>mult.xq</code> placed in the HTTP directory:<br/><code>http://localhost:8984/rest?run=mult.xq&$a=21&$b=2</code>
<pre classsyntaxhighlight lang="brush:xquery">
(: XQuery file: mult.xq :)
declare variable $a as xs:integer external;
declare variable $b as xs:integer external;
<mult>{ $a * $b }</mult>
</presyntaxhighlight>
The dollar sign can be omitted as long as the variable name does not equal a parameter keyword (e.g.: <code>method</code>).
If <code>query</code> or <code>run</code> is used as operation, external variables can be specified via the <code><variable/></code> element:
<pre classsyntaxhighlight lang="brush:xml">
<query xmlns="http://basex.org/rest">
<text><![CDATA[
<variable name="b" value="2"/>
</query>
</presyntaxhighlight>
=Response=
<code>org.basex.util.Base64</code> can be used for that purpose:
<pre classsyntaxhighlight lang="brush:java">
import java.net.*;
import org.basex.util.*;
}
}
</presyntaxhighlight>
===Content-Types===
the connection (in this example we explicitly store the input file as raw):
<pre classsyntaxhighlight lang="brush:java">
// store input as raw
conn.setRequestProperty("Content-Type", "application/octet-stream");
</presyntaxhighlight>
See the [[REST#PUT Requests|PUT Requests]] section for a description of the possible content-types.
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu