Skip to main content

REST API

An alternative to the JS SDK to connect to your backend is through the REST API.

The slug of the entity is by default the plural dasherized name of the entity, but you can change it in the params

All entities start with the api prefix followed by collections for collections and singles for single entities.

Examples:

  • http://localhost:1111/api/collections/cats gets the list of the cats
  • http://localhost:1111/api/singles/home-content gets the home content
tip

An OpenAPI documentation for the REST API is automatically generated on http://localhost:1111/api. Have a look!

Collections

GET /slug

Gets a list of items from an entity.

Filters

You can filter by property to refine the list of items. Use suffix to pass logic to it:

SuffixDescriptionExample
_eqequalsisActive_eq=true
_neqnot equalsname_neq=alice
_gtgreater thanbirthdate_gt=2020-01-01
_gtegreater than or equalage_gte=4
_ltless thanamount_lt=400
_lteless than or equalamount_lte=400
_likelikename_like=%bi%
_inincluded incustomer_in=1,2,3

By default the results are ordered by id in a DESC order and thus shows the new ones first.

Relations

Load relations

You can specify the relations you want to load. Eager relationships are loaded by default.

// Loads cats and their owners.
GET http://localhost:1111/api/collections/cats?relations=owner

// Coma-separated relations.
GET http://localhost:1111/api/collections/invoices?relation=project,customer

// Nested relations.
GET http://localhost:111/api/collections/city?relations=region,region.country
Filter by relations

Once the relation is loaded, you can also filter by its properties using the same filters suffixes:

GET http://localhost:1111/api/collections/cats?relations=owner&owner.id_eq=1
GET http://localhost:1111/api/collections/cats?relations=owner&owner.name_eq=Jorge

Pagination

All list requests are paginated by default. Just use the page parameter to chose your page and the perPage param if you want to change the number of items per page.

Response format
{
"data": [{...}, {...}],
"currentPage": 1,
"lastPage": 10,
"from": 1,
"to": 10,
"total": 100,
"perPage": 10
}
ParamDescriptionExample
pageThe number of the page requestedpage=3
perPageThe number of items of each pageperPage=40

Order

Order your list by a defined property.

ParamDescriptionExample
orderByThe name of property you want to order by.orderBy=age
orderAscending 'ASC' or Descending 'DESC'order=DESC

GET /slug/:id

Get a single item.

POST /slug

Create a new item.

Provide a Request Payload in JSON:

Request body
{
"age": 2
"name": "Milo"
}

PUT /slug/:id

Update an item.

Provide a Request Payload in JSON:

Request body
{
"age": 2
"name": "Milo"
}

DELETE /slug/:id

Delete an item.

Singles

On single entities, there is one item only so we do not need to specify the id.

GET /slug

Gets the single record.

Response format
{
"title": "New home title",
"showCarousel": true
}

PUT /slug

Update the single record

Provide a Request Payload in JSON:

Request body
{
"title": "New home title",
"showCarousel": true
}