Skip to content

Entity Rest Api Breakdown

All entities automatically expose a rest API based on the parameters defined in its decorator.

The API supports the following actions (we'll use the products entity as an example, and a specific product with an id=7):

Http MethodDescriptionexamplerequires
GETreturns an array of rows/api/productsallowApiRead
GETreturns a single row based on its id/api/products/7allowApiRead
POSTcreates a new row based on the object sent in the body, and returns the new row/api/productsallowApiInsert
PUTupdates an existing row based on the object sent in the body and returns the result/api/products/7allowApiUpdate
DELETEdeletes an existing row/api/products/7allowApiDelete

Sort

Add _sort and _order (ascending order by default)

https://mySite.com/api/products?_sort=price&_order=desc

Filter

You can filter the rows using different operators

https://mySite.com/api/products?price.gte=5&price.lte=10

Filter Operators

operatordescriptionexample
noneEqual Toprice=10
.neNot Equalprice.ne=10
.inis in json arrayprice.in=%5B10%2C20%5D (url encoded - [10,20])
.containsContains a stringname.contains=ee
.notContainsNot contains a stringname.notContains=ee
.startsWithStarts with a stringname.startsWith=ee
.endsWithEnds with a stringname.endsWith=ee
.gtGreater thanprice.gt=10
.gteGreater than or equalprice.gte=10
.ltLesser thanprice.lt=10
.lteLesser than or equalprice.lte=10
.nullis or is not nullprice.null=true
  • you can add several filter conditions using the & operator.

Count

https://mySite.com/api/products?price.gte=10&__action=count

returns:

JSON
{
  "count": 4
}

Paginate

The default page size is 100 rows.

https://mySite.com/api/products?_limit=25
https://mySite.com/api/products?_limit=5&_page=3

TIP

You can use it all in conjunction:

https://mySite.com/api/products?price.gte=5&price.lte=10&_sort=price&_order=desc&_limit=5&_page=3

MIT Licensed | Made by the Remult team with ❤️