RPC systems
November 3, 2019 ยท View on GitHub
The examples below are specific to REST.
REST specifies the data argument with the request
payload, the id argument with the URL and the command
with the protocol method. However other RPC systems have
different conventions.
Find command
To retrieve a specific model, use the find command.
GET /rest/users/
{
"data": [
{ "id": "1", "name": "Anthony" },
{ "id": "2", "name": "Tom" },
{ "id": "3", "name": "Anna" }
]
}
To retrieve only one model, specify the model id.
GET /rest/users/1
{
"data": { "id": "1", "name": "Anthony", "manager": "3" }
}
Create command
The create command creates new models.
The data argument is either a single model:
POST /rest/users/5
{ "id": "5", "name": "David" }
{
"data": { "id": "5", "name": "David" }
}
or several models:
POST /rest/users/
[
{ "name": "David" }
{ "id": "5", "name": "Alex" }
]
{
"data": [
{ "id": "9b6c5433-4f6a-42f3-9082-32c2eae66a7e", "name": "David" },
{ "id": "5", "name": "Alex" }
]
}
If the id attributes are omitted, a unique ID will be set.
POST /rest/users/
{ "name": "David" }
{
"data": { "id": "9b6c5433-4f6a-42f3-9082-32c2eae66a7e", "name": "David" }
}
Upsert command
The upsert command performs a full modification of existing models. If the
models do not exist, they are created instead.
The data argument is either a single object or an
array of objects.
Each model must contain an id attribute.
PUT /rest/users/4
{ "id": "4", "name": "David" }
{
"data": { "id": "4", "name": "David" }
}
With several models:
PUT /rest/users/
[
{ "id": "4", "name": "David" }
{ "id": "5", "name": "Alex" }
]
{
"data": [
{ "id": "4", "name": "David" },
{ "id": "5", "name": "Alex" }
]
}
Patch command
The patch command performs a partial modification of existing models.
The data argument is a single object specifying the
new values to update.
It cannot contain any id attribute.
PATCH /rest/users/1
{ "city": "Copenhagen" }
{
"data": { "id": "1", "name": "Anthony", "city": "Copenhagen" }
}
With several models:
PATCH /rest/users/
{ "city": "Copenhagen" }
{
"data": [
{ "id": "4", "name": "David", "city": "Copenhagen" },
{ "id": "5", "name": "Alex", "city": "Copenhagen" }
]
}
Advanced patch commands are also available, for example:
PATCH /rest/users/1
{ "age": { "_add": 1 } }
More information can be found here.
Delete command
The delete command removes existing models.
DELETE /rest/users/1
{
"data": { "id": "1", "name": "Anthony", "manager": "3" }
}
With several models:
DELETE /rest/users/
{
"data": [
{ "id": "4", "name": "David", "city": "Copenhagen" },
{ "id": "5", "name": "Alex", "city": "Copenhagen" }
]
}