Most browsers can be used to get to know the REST API, and to directly display the results.
When requesting the first result, you will have to enter some database credentials
(default: <code>admin</code>/<code>admin</code>, [[#User Management|see below]]).Alternatives Some alternatives for using REST are listed in the [[#Usage Examples|Usage Examples]] below.
==URL Architecture==
In the given example, a single XML document is stored in the ''factbook'' database:
:<code>[http://admin:admin@localhost:8984/rest/factbook http://admin:admin@localhost:8984/rest/factbook]</code>
<pre class="brush:xml">
The contents of a database can be retrieved by directly addressing the resource:
:<code>[http://admin:admin@localhost:8984/rest/factbook/factbook.xml http://admin:admin@localhost:8984/rest/factbook/factbook.xml]</code>
If a resource is not found, an HTTP response will be generated with <code>404</code> as status code.
; Examples
* The first example lists all resources found in the '''tmp''' path of the ''xmark'' database:<br/><code>[http://admin:admin@localhost:8984/rest/factbook/tmp http://admin:admin@localhost:8984/rest/factbook/tmp]</code>
* The first example prints the city names from the ''factbook'' database and encloses all results with a <code><rest:result/></code> elements:<br/><code>[http://admin:admin@localhost:8984/rest/factbook?query=//city/name&wrap=yes http://admin:admin@localhost:8984/rest/factbook?query=//city/name&wrap=yes]</code>
* In the next request, <code>US-ASCII</code> is chosen as output encoding, and the query <code>eval.xq</code> is evaluated:<br/><code>[http://admin:admin@localhost:8984/rest?run=eval.xq&encoding=US-ASCII http://admin:admin@localhost:8984/rest?run=eval.xq&encoding=US-ASCII]</code>
* The next URL turns on XML wrapping and lists all database users that are known to BaseX:<br/><code>[http://admin:admin@localhost:8984/rest?command=show+users http://admin:admin@localhost:8984/rest?command=show+users]</code>
===POST Requests===
Complete request (compact notation, omitting the optional variable declaration):
:<code>http://admin:admin@localhost:8984/rest?query=$x&$x=21</code>
===POST Requests===
==User Management==
By default, the HTTP server is started with no predefined user. Users and passwords can besent via [http://en.wikipedia.org/wiki/Basic_access_authentication HTTP basic authentication]with each HTTP request. As alternative, users and passwords can also be stored server-side in the"org.basex.user" and "org.basex.password" system properties before the HTTP server is started,or specified as [[Startup Options#BaseX HTTP Server|command-line arguments]].
With cURL, and most browsers and with cURL, you can specify the user name andpassword with each HTTP request within the request string as plain text,using the format <code>USER:PASSWORD@URL</code>. An example:
: <code>http://admin:admin@localhost:8984/rest/factbook</code>