Skip to content
kumy edited this page Aug 20, 2017 · 15 revisions

Example Calls

What follows are several example calls to the API. Each example should be matched by an example call in the demo project. Several words are reserved for use by the API. In some cases, an alias for the reserved word also exists. A complete list is available here.

The examples will work on a fictional end point USERS and demonstrated in the sister application. In most cases, multiple modifiers can be chained together such as search for a specific value and limiting the number or records returned.

GET

/

This URL will show a sort of sitemap for the API. It describes all routes and VERBS supported by the api.

Notice that the API supports versioning, all subsequent examples will use a default "v1" incorporated into the URL but this is arbitrary and defined by YOU the developer.

/v1/users

Show all available records stored in the API

/v1/users/1

Show only the user record with an ID of 1.

/v1/users?limit=5

Show the first 5 user records. (Aliases: per_page, perPage)

/v1/users/?limit=5&offset=2

Show the 2nd group of 5 records. Useful for displaying paginated result sets. (Aliases: page)

/v1/users/?sort=last_name

Sort the resulting records by any value known to that table or tables related by a hasOne relationship. Default is to sort in descending order. To sort in ascending order, prefix the field name with a dash. ie. /v1/users/?sort=-last_name. To sort by multiple fields, separate each field by a comma. ie. /v1/users?sort=-last_name,+first_name (Aliases: sort_field, sortField)

/v1/users/?last_name=Watson

Show only records that contain a last_name value of "Watson". Searches are performed by the underlying SQL database. Depending on the character encoding of the database and table, searches may be case sensitive or not.

/v1/users?last_name=Watkins&first_name=Sean

The API supports filtering by multiple fields and treats each additional filter as an AND when searching.

/v1/users/?last_name=wat*

A wildcard filters records to only include those with a last_name that begins with "wat". Several variations on this are builtin such as last_name=wat or last_name=*wat.

/v1/users/?last_name=Watson||Watkins

Search for multiple values in the same field by concatenating search values with a double pipe as in...||.

/v1/users?with=addresses

Side load related tables. The API supports side loading one or more specific tables separated by commas. (Alias: include)

Since each end point can be configured to auto sideload some or all related tables. The API will sideload all tables with the value "all" and will not sideload any tables with the value "none".

/v1/addresses?with=users&users:last_name=Watson

The API supports searches against columns in a joined table. In this case, only return address records where the user's last_name field equals "Watson".

To reference a related table's field, use this syntax: TABLE:FIELD.

/v1/users?age=%3E80 or /v1/users?age=%3C21

User comparison operators such as > or <. Possible supported operators are:
>, >=, <=, <

These characters should be URL encoded as described here.
ie. /v1/users?age=<21 becomes /v1/users?age=%3C21

/v1/users/?last_name=Watson||Watkins&count

The API allows to return only the meta data of a request to get only counters instead of the full response. This is achieved by adding the parameter count to the query string.