Syntax

Your implementation of apicalypse can stretch the language any way you feel. Use the validation tool to experiment for your own purposes.

Here is a recommendation for simple xml/json apis…

fields a,b,c;
exclude d,e,f;
where b.count >= 14 & a != n;
limit 8;
offset 2;
sort b.count desc;
search "test";

fields

A comma separated array of fields.

Examples fields id,name,description

exclude

A comma separated array of fields.

Examples exclude name,description

where

A data filter query, similar to SQL.

You can use & and | to join comparitors (AND and OR respectively).

Operators:

  • = equals
  • != not equals
  • > is larger than
  • >= is larger than or equal to
  • < is smaller than
  • <= is smaller than or equal to
  • [] contains all of these values
  • ![] does not contain all of these values
  • () contains at least one of these values
  • !() does not contain any of these values
  • {} contains all of these values exclusively

Examples

A simple filter for entries where the id is 55.

where id = 55

Instead of specific values, you can also use null, true and false.

where enabled = true

Given the column genres contains a single number, we can filter results with parenthesis () to check if it contains any of those values. If the genre is 1, 2 or 3, it will be returned in the results.

where genres = (1,2,3)

Given the column genres is an array of numbers, we can use the in operator [] to ensure all specified values appear in the array. In the example below, if genres does not include 1 and 2 and 3, it will not be matched.

where genres = [1,2,3]

Given the column genres is an array of numbers, we can use the exclusive operator {} to ensure only the specified values appear in the array. In the example below, if genres only contains 1 and 2, it will be matched.

where genres = {1,2}

As per the example above, when only looking for a single value, you can do the following…

where genres = 1 is the same as where genres = {1}

limit

The number of items to return. This usually has a maximum limit.

limit 10

offset

The index to start returning results.

offset 25

sort

Sort results by a certain field’s values and the use asc or desc to sort by ascending or descending order.

sort date desc

Search for values on a column.

search description "Foo"

It is recommended to have a default column, then a column name does not need to be supplied.

search "Foo"