REST Services

Docxpresso comes equipped with a configurable REST Service that simplifies the task to query Docxpresso databases from a remote server.

All data transactions are securized via the use of HMAC so only authorized clientes may download any data.

One may create a particular service to query the database in two different ways via:

  • Custom queries: that require to create a JSON object with the required structure.
  • SQL queries: that allow to create a standard and arbitrarily complex SQL query.

Custom queries

You should use the Custom query web interface to include:

  • A unique name (slug) that identify the query.
  • A JSON object which structure will be defined below.

The JSON object must include the following properties:

  • resource: the table to be queried: 'resources','rpcs', 'validations', 'categories', 'usage' => 'template_usage', 'versions', 'templates', 'groups' and 'users'.
  • select: an array with the firlds to display.
  • where: an array of objects with the following properties:
    • field: the field used for the where clause.
    • operand: the required operand that may be any of the following: 'LIKE', 'NOT LIKE', '>', '<', '<=', '>=','=' (default value), '!=', 'REGEXP', 'NOT REGEXP', 'IN' and 'NOT IN'.
  • orderBy: an object with the properties field (the name of the field that we should use for the ordering) and type ('ASC' or 'DESC').
  • maxResults: an integer indicating the maximum numbre of results.
  • offset: an integer indicating the required offset.

For example, the following custom query:

{
  "resource" : "templates",
  "select": ["id","name"],
  "where" : [
    {"field" : "id", "operand" : "IN"},
    {"field" : "description", "operand" : "LIKE"}
  ],
  "orderBy" : {"field" : "created", "type" : "ASC"}
}

Will return an associative array with the select fields of the templates table where the values for the id and description fields used in the query should be provided by GET parameters.

SQL queries

This method is designed so one may query the database with an arbirarily complex SQL queries.

In order to use this option for anything beyond a simple SELECT you require of a deep knowledge of the Docxpresso database.

You need to include in the SQL query web interface:

  • A unique name (slug) that identify the query.
  • The SQL query that you want to be remotely run (you should avoid queries that missused my damage data integrity).

For example, the following custom query:

SELECT name, description FROM Templates WHERE id = ?

Will return an associative array with the select fields of the templates table where the values for the id field used in the query should be provided by a GET parameter.