Skip to main content

Mutations

The generated controller provides create, update, and delete endpoints for a single record. Mutation bodies are ordinary JSON and are described in OpenAPI using the configured create and update DTOs.

Create one

POST /todo-items
Content-Type: application/json

{
"title": "Write REST documentation",
"completed": false
}

A successful create returns 201 Created with the serialized record.

{
"id": 1,
"title": "Write REST documentation",
"completed": false
}

Update one

PUT /todo-items/1
Content-Type: application/json

{
"completed": true
}

A successful update returns 200 OK with the updated record. Make update DTO properties nullable/optional so clients can submit partial updates.

Delete one

DELETE /todo-items/1

A successful delete returns 200 OK with the deleted record data supplied by the query service.

Set useSoftDelete: true when the persistence adapter and service support soft deletion:

{
DTOClass: TodoItemDTO,
EntityClass: TodoItemEntity,
delete: { useSoftDelete: true }
}

Disable or customize mutations

{
DTOClass: TodoItemDTO,
EntityClass: TodoItemEntity,
create: { disabled: true },
update: {
one: { path: ':id', guards: [EditorGuard] }
},
delete: {
useSoftDelete: true,
one: { path: ':id/archive', description: 'Archive a task' }
}
}

You can also supply custom CreateOneInput or UpdateOneInput classes when the generated body type is not sufficient. For application-level transformations, use hooks; for record-level access rules, use authorization.