REST Server
How to expose GET|POST|PUT|DELETE endpoints in you application
Define new endpoint
./rest/article-fetch.json
{
"path": "/articles/{articleId}", //{articleId} - variable name
"methods": [ //POST, GET, DELETE, PATCH,
"GET"
],
"query": "article-fetch-single",
"authorized": false //if set to true, only users logged in via admin panel can access this route
}
./queries/article-fetch-single.json
{
"type": "sql-select",
"id": "article-fetch-single",
"connection": "main-database",
"query": "SELECT a.id as articleId, a.content as articleContent FROM article as a where a.id = :articleId",
"resultType": "single",
"params": [
{
"paramName": "articleId",
"type": "int",
"required": true
}
]
}
Accessing data send in http request
If you create rest endpoint like this and send post request like this one
POST /articles/{subGroupId}?userId=123&groupIds[]=456&groupIds[]=789
{
"content": "this is content",
"active": true,
"complexStructure": {
"a": "b"
},
"list": [
"c",
"d"
]
}
Query that is run in this endpoint will have access to following params:
- subGroupId
- userId
- groupIds
- content
- active
- complexStructure
- list
You can attach any query:
- Select one item from database
- Select many items from database
- Insert new record
- Update record
- Delete record
- Call external rest endpoint
- Run transaction
Last modified April 16, 2024: content fix (a2d9b96)