Skip to main content

Create

Create Resource

This entrypoint creates a new resource.

  • POST /{base_url}

Parameters

NameTypeInDescriptionDefault
include_permissionsbooleanqueryWhether to include document permissionstrue

Example

request

curl \
-X POST \
-H "Accept: application/json" \
https://example.com/users \
-d '{ "name": "Jane" }'

response

Status: 201
{
"_id": "5d6ede6a0ba62570afcedd3b",
"name": "Jane",
"address": null,
"roles": ["user"],
"creditBalance": 0,
"loginDate": null
}

Create Resource - Advanced

This entrypoint creates a new resource and returns selective data fields.

  • POST /{base_url}/__mutation
  • The suffix __mutation can be configured using a model option, as demonstrated below:
    modelRouter.set('mutationPath', '_mutable_');

Parameters

NameTypeInDescriptionDefault
include_permissionsbooleanqueryWhether to include document permissionstrue
dataobjectbodyDocument data to create
selectobject │ array[string]bodyDocument fields to include or exclude after the creation
populatearray[string] │ array[object]bodyDocument fields to populate after the creation
options.includePermissionsbooleanbodyWhether to include document permissionstrue
options.populateAccess'list' │ 'read'bodyThe access level to use in populate methodread

Example

request

curl \
-X POST \
-H "Accept: application/json" \
https://example.com/users/__mutation \
-d '{
"data": { "name": "Jane" },
"select": ["name", "address"],
"populate": ["address"],
"options": {
"includePermissions": true,
"populateAccess": "list",
}
}'

response

Status: 201
{
"_id": "5d6ede6a0ba62570afcedd3b",
"name": "Andrew Jackso",
"address": {
"city": "Seattle",
"country": "USA"
},
"_permissions": {
"edit": false
}
}