Changes

Jump to navigation Jump to search
181 bytes added ,  16:41, 3 November 2023
no edit summary
This page presents one of the [[Web Application]] services. It describes how to use the REST API of BaseX.
BaseX offers a RESTful API for accessing database resources via URLs.REST ([https://en.wikipedia.org/wiki/Representational_State_Transfer REpresentational State Transfer])facilitates a simple and fast access to databases through HTTP. The HTTP methodsGET, PUT, DELETE, and POST can be used to interact with the database.
=Usage=
==GET Method==
If the GET method is used, all query parameters are directly specified within the URL.Additionally, the following '''operations''' can be specified:
* {{Code|query}}: Evaluate an XQuery expression. If a database or database path is specified in the URL, it is set as query context.
* {{Code|command}}: Execute a single [[Commands|database command]].
* {{Code|run}}: Evaluate an XQuery file or command script located on the server. The file path is resolved against the {{Option|RESTPATH}} directory. Similar to {{Code|query}}, a database or database path is set as context. With {{Announce|Version 11}}, if no file is found and if the file suffix has been omitted, the extensions {{Code|.xq}} and {{Code|.bxs}} are successively attached to the supplied filename.
; Examples
* Lists all resources found in the '''tmp''' path of the ''factbook'' database:<br/><code>http://localhost:8080/rest/factbook/tmp</code>
 
* Returns the number of documents in a database called ''test'':<br/><code>http://localhost:8080/rest/test?query=count(.)</code>
 * Serializes a document as JSONMLJsonML:<br/><code>http://localhost:8080/rest/factbook/factbook.xml?method=json&json=format=jsonml</code> * <code>US-ASCII</code> is chosen as output encoding, and the query <code>eval.xq</code> is evaluated:<br/><code>http://localhost:8080/rest?run=eval.xq&encoding=US-ASCII</code> * The next URL lists all database users that who are known to BaseX:<br/><code>http://localhost:8080/rest?command=show+users</code>
==POST Method==
* The contents of the HTTP body will be taken as input for the document <b>one.xml</b>, which will be stored in the <b>XMark</b> database:<br/><code><nowiki>http://localhost:8080/rest/XMark/one.xml</nowiki></code>
An HTTP response with status code <code>201</code> (CREATED)is sent back if the operation was successful. Otherwise,the server will reply with <code>404</code> (if a specifieddatabase was not found) or <code>400</code> (if the operationcould not be completed).
Have Take a look at the [[REST#Usage Examples|usage examples]] for more detailed examples using Java and shell tools like cURL.
==DELETE Method==
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu