Skip to main content

Update a Model

Now that you have a stack up and running, we can tackle the standard use case of an update of a model.

curl http://localhost:3001/api/templates/examples/users_with_lastname.json | \
curl -X POST 'http://localhost:3001/api/admin/users' \
-H 'Authorization: token' \
-H 'Content-Type: application/json' \
-d @- | jq

The users model will now accept a lastname:

curl -X GET 'http://localhost:3001/api/admin?model=users' \
-H 'Authorization: token' \
-H 'Content-Type: application/json' | \
jq '{model: .users.schema.model}'
{
"model": {
"additionalProperties": true,
"properties": {
"firstname": {
"type": "string"
},
"lastname": {
"type": "string"
}
}
}
}
caution

In production (ie. NODE_ENV=production), models are not updated in realtime and you must restart the datastore to release the model change effectively.

Let's now set the lastname of Alice:

curl -X POST 'http://localhost:3001/api/users/617afd8106ff040013a7214c' \              
-H 'Authorization: token' \
-H 'Content-Type: application/json' \
-d '{
"lastname": "Doe"
}' | jq
# {
# "created_at": "2021-10-28T19:44:01.658Z",
# "firstname": "Alice",
# "updated_at": "2021-10-28T19:44:16.010Z",
# "version": 1,
# "user_id": "617afd8106ff040013a7214c",
# "lastname": "Doe"
# }

That's it!