Skip to main content

REST API

While a lot of this documentation and sample code from the SDK is focused on interaction with ApertureDB over TCP connection, port 55555, ApertureDB provides an alternate communication modality over HTTP. This is typically made available on a different port, perhaps 443 for HTTPS (recommended) or 80 for HTTP.

All the queries that ApertureDB clients send over TCP can also be sent to ApertureDB over HTTP with RESTish calls. You can also use this interface to build your own client if you are using an unsupported language.

REST interface to ApertureDB.

The REST layer is a very simple wrapper of the TCP endpoint. When an instance of ApertureDB is brought up, it listens on port 80 for REST-based queries.

There is a single endpoint for all the queries, and that is /api.

From a HTTP client, the type of requests that work are POST methods, transmits the request as a payload, but uses multi-part form data to create message to be sent. The message itself is in the form of

  • a field called query, i.e JSON query (which is a list of commands),
  • multiple blobs fields that have the raw bytes that need to be transmitted as blobs.

The response will also be multi-part form data and will contain:

  • A field called json containing the JSON response
  • multiple *blobs fields that have the raw bytes for any blobs being returned
Authentication and Authorization
  • All the queries made in this manner also rely on a Authorization header with value as Bearer <token> to be accepted by ApertureDB server.
  • This <token> is obtained from an Authenticate command to the Server, which is a special type of query that does not need a Authorizarion header. The command looks like:
{
"Authenticate": {
"username": "username",
"password": "password"
}
}

A successfull response to this command, consists of a session_token and a refresh_token. The value for the session_token is to be used as the token that goes in the Authorizaition header for all authenticated requests.

Example queries.

const request = (query, blobs, handler, sessionToken) => {
apiURL = "https://<hostname>:<port>/api"
const formData = new FormData();
formData.append('query', JSON.stringify(query));
displayContent(query, response=false);

blobs.forEach(element => {
formData.append('blobs', element);
});

let headers = null;
if (sessionToken != null){
console.log(`setting session token ${sessionToken}`);
headers = {
"Authorization": `Bearer ${sessionToken}`
}
}

axios.post(
url=apiURL,
data=formData, {
headers: headers
}).then((response)=>{
handler(response.data)
})
}

get_schema = () => {
//Get a refresh token.
auth = [{
"Authenticate": {
"username": "username",
"password": "password"
}
}]
request(query = auth, blobs = [], handler = (data)=>{
authData = data["json"];
sessionToken = authData[0].Authenticate.session_token;
query = [{
"GetSchema" : {

}
}]
request(query=query, blobs=[], handler = (data)=>{
console.log(data["json"])
})
}

get_schema()

Resources

The sample reference code is available under rest_api

FileDescriptioninstructions
rest_api.pyInteractions with ApertureDB using python's requestspython rest_api.py
rest_api.jsInteractions with ApertureDB using javascript with axiosIs included in index.html
index.htmlA web page that renders from responses from ApertureDBTested on chrome