You can basically use any routes as you want without need to define them, just be sure to make it plural to get the population system work as expected.
Plural routes
GET /postsGET /posts/1POST /postsPUT /posts/1PATCH /posts/1DELETE /posts/1
Filter by equality
You can filter by any by using field=value, Use . to access deep properties
You can use $select to return only the fields that you need.
Advanced filters
You can use different modifiers in order to perform special queries:
# Format GET/resources?field:modifier=value# orGET/resources?field:modifier:coerce=value# where coerce can be "id", "date", or "number"# bool: Boolean CoercionGET/comments?seen:bool=true# date: date CoercionGET/comments?createdAt:date=2019-08-15T20:01:17.065ZGET/comments?createdAt:date=1565899340489# id: Object Id CoercionGET/comments?variableStoredAsObjectId:id=5d392ddb3aac2900173a876a# number: Number CoercionGET/comments?points:number=10# ne: Not EqualGET/comments?name:ne=Vektor# lt: Lower thanGET/comments?points:lt=10# gt: Greater thanGET/comments?points:gt=10# lte: Lower than or equalGET/comments?points:lte=10# gte: Greater than or equalGET/comments?points:gte=10# i:GET/comments?fruits:in=appleGET/comments?fruits:in[]=apple&fruits:in[]=banana# nin:GET/comments?fruits:nin=appleGET/comments?fruits:nin[]=apple&fruits:nin[]=banana# size GET/items?fruits:size=10
Pick fields to return
GET /posts?$select[]=author&$select[]=_idGET /posts?$select=name
GET /posts?$page=7
Paginate
Use $page and optionally $limit to paginate returned data. keep in mind that the first page is 0 `$page=0`
GET /posts?$page=7&$limit=20
10 items are returned by default
Sort
Add $sort and $order (ascending order by default)
GET /posts?$sort=views&$order=ascGET /posts/1/comments?$sort=votes&$order=asc
For multiple fields, use the following format:
GET /posts?$sort=user&$sort=views&$order[]=desc$$order[]=asc
Count
Use $count to get an answer with the total document count
GET /posts?$count=1
response:
{"count":10}
Advanced queries
Use $query to send a JSON with any mongodb query
GET /posts?$query={"name":"Puky"}
Regular Expressions (Regex)
Use $regex to send a regex Query
GET /posts?$regex=["FieldName","Regex","flags"]
# the regex value should be a valid Js Array
Full-text search
Coming soon...
Relationships
To include children resources, add $populate
GET /companies$populate=employees
// create two companiesawaitdb.collection('companies').insertOne({ _id:1, name:'corp' });awaitdb.collection('companies').insertOne({ _id:2, name:'inc' });// this employee works in company 1, notice the using of singular word for companiesawaitdb.collection('employees').insertOne({ _id:1, name:'Foobio', company_id:1 });// this employee works for both!, notice the "s" on company_ids!awaitdb.collection('employees').insertOne({ _id:2, name:'Barfy', company_ids: [1,2] });constr=awaitrequest(server).get('/companies?$populate=employees').expect(200);// employees are populated"a.equal(r.body[0].employees.length,2);a.equal(r.body[1].employees.length,1);
To do the opposite, add parent resources use $fill in the query.
GET /employees?$fill=companies
Flags
Sometimes you want to pass some data that are neither queries or filters, to be used in the route logic, permissions or filters. you can use them with query flags:
GET /employees?$$flag=someData&$$anotherFlag=moreData
Geo Filters (Coming Soon)
# intersectGET/countries?location:geo:ins:polygon=[[]]GET/countries?location:geo:ins:multipolygon# withinGET/countries?location:geo:win:polygon=[[]]GET/countries?location:geo:win:multipolygon=[[]]# Near PointGET/countries?location:geo:near=[LONG,LAT,MIN,MAX]