Optional Parameters â
These parameters provide a flexible way to modify API requests or plan commands. Use them to apply filters, specify sorting options, or include additional data as needed. Their function remains consistent across both API requests and plan commands.
All parameters are described in the table below:
| Parameter | Usage | GET select | POST insert | PATCH update | DELETE delete | JS Context | Metal version |
|---|---|---|---|---|---|---|---|
đfilter | simple filter | đĸ | - | đĸ | đĸ | $schema, $entity | v0.4+ |
đfilter-expression | complex filter expression | đĸ | - | đĸ | đĸ | $schema, $entity | v0.4+ |
đfields | select fields to return | đĸ | - | - | - | $schema, $entity | v0.4+ |
đsort | sort data with a given order | đĸ | - | - | - | $schema, $entity | v0.4+ |
cache | cache returned data for a given time | đĸ | - | - | - | N/A | v0.1+ |
đâī¸data | data to send to provider | - | đĸ | đĸ | - | $schema, $entity | v0.4+ |
đ: Supports JavaScript Expression Engine (see: JavaScript Expression Engine)
âī¸: supports Field Escape Engine (see: Field Escape Engine)
How Optional Parameters are handled by Data Providers â
| Data Provider | data | filter | filter-expression | fields | sort | cache |
|---|---|---|---|---|---|---|
| Azure SQL Database/Microsoft SQL Server | đĩ | đĩ | đĩ | đĩ | đĩ | đĸ |
| Files | đĸ | đĸ | đĸ | đĸ | đĸ | đĸ |
| Memory | đĸ | đĸ | đĸ | đĸ | đĸ | đĸ |
| Metal Server | đĩ | đĩ | đĩ | đĩ | đĩ | đĩ |
| MongoDB | đĩ | đĩ | đĩ | đĩ | đĩ | đĸ |
| MySql | đĩ | đĩ | đĩ | đĩ | đĩ | đĸ |
| Plan | - | đĸ | đĸ | đĸ | đĸ | đĸ |
| PostgreSQL | đĩ | đĩ | đĩ | đĩ | đĩ | đĸ |
| WebService | đĄ | đĸ | đĸ | đĸ | đĸ | đĸ |
| Cosmos DB | đĩ | đĩ | đĩ | đĩ | đĩ | đĸ |
đĩ Handled natively by the data provider driver
đĄ Partially handled by the data provider driver
đĸ Handled by Metal Server
Parameters â
filter â
Simple filtering feature by providing fields and values.
Supports JavaScript Expression Engine.
Example
To filter people with
name = Johnandlocation = USA:GET Request
httpGET /schema/my-schema/my-entity ?filter={"Name":"John","Location":"USA"}PATCH Request
httpPATCH /schema/my-schema/my-entity Content-Type: application/json { "filter": { "Name": "John", "Location": "USA" } }DELETE Request
httpDELETE /schema/my-schema/my-entity Content-Type: application/json { "filter": { "Name": "John", "Location": "USA" } }
filter-expression â
Free expression for more complex data filtering expressed in SQL-like syntax.
Supports JavaScript Expression Engine.
Example
GET Request
httpGET /schema/my-schema/my-entity ?filter-expression=name LIKE '%%ing'PATCH Request
httpPATCH /schema/my-schema/my-entity Content-Type: application/json { "filter-expression": "name LIKE '%ing' " }DELETE Request
httpDELETE /schema/my-schema/my-entity Content-Type: application/json { "filter-expression": "name LIKE '%ing' " }
âšī¸ NOTE
When employing the LIKE operator with the wildcard % in a GET method, remember to escape it using double %%.
Example:
filter-expression=name LIKE '%%ing'
fields â
Select fields to return.
Supports JavaScript Expression Engine.
Example
httpGET /schema/my-schema/my-entity ?fields="name, country"
sort â
sort data with given order.
Supports JavaScript Expression Engine.
| Sorting Operator | Usage | SQL like |
|---|---|---|
asc | Ascending order | ASC |
desc | Descending order | DESC |
Example
To sort data with
nameascending thenhttpGET /schema/my-schema/my-entity ?sort={"name": "asc","email": "desc"}
cache â
Instruct Metal to cache the data returned from the source for a given time in seconds before displaying it to the user end point, meanwhile users that hit again the same query will receive the cached data until it expires.
Example
To cache returned data for 60 seconds:
httpGET /schema/my-schema/my-entity ?cache=60
data â
this paramater is used for inserting or updating data.
Supports JavaScript Expression Engine and Field Escape Engine only for updates (see: Field Escape Engine)
Inserting data â
:data accept whether a JSON object if it is a single row to insert or a JSON Array if many rows
Example: single row insert
Request
httpPOST /schema/my-schema/my-entity Content-Type: application/json { "data": { "name":"Facebook", "color": "blue" } }Response
httpHTTP/1.1 201 Created
Example: multiple rows insert
Request
httpPOST /schema/my-schema/my-entity Content-Type: application/json { "data": [ { "name":"Facebook", "color": "blue" }, { "name":"YouTube", "color": "red" } ] }Response
httpHTTP/1.1 201 Created
Updating data â
:data accept a JSON object of key:value where key is the field to modify and value is the new value
Example
Request
httpPATCH /schema/my-schema/my-entity Content-Type: application/json { "data": { "name":"Facebook", "color": "blue" } }Response
httpHTTP/1.1 204 No Content