Automatic CRUD in Detail
Automatic CRUD in Detail
~16 Min. Lesezeit Zuletzt aktualisiert am August 8, 2026
Chapter 9 showed THAT #[ApiResource] creates CRUD endpoints – now let's go through EACH one systematically, with REAL curl calls against our Project resource.
GET /api/projects: listing all projects
curl -k -H 'Accept: application/json' https://localhost/api/projectsPOST /api/projects: creating a new project
curl -k -X POST https://localhost/api/projects \
-H 'Content-Type: application/json' \
-d '{"name": "Website Relaunch", "description": "Complete redesign"}'{
"@context": "/api/contexts/Project",
"@id": "/api/projects/1",
"@type": "Project",
"id": 1,
"name": "Website Relaunch",
"description": "Complete redesign",
"createdAt": "2026-08-06T12:00:00+00:00"
}Responds with status 201 Created AND the COMPLETE object, now populated with a generated id and createdAt – WITHOUT us writing a single line of controller code. Content-Type: application/json in the request header MATTERS: API Platform expects application/ld+json by default for writes, but also accepts plain JSON.
GET /api/projects/{id}: fetching a single project
curl -k -H 'Accept: application/json' https://localhost/api/projects/1PUT /api/projects/{id}: fully updating
curl -k -X PUT https://localhost/api/projects/1 \
-H 'Content-Type: application/json' \
-d '{"name": "Website Relaunch v2", "description": "Updated description"}'Achtung: PUT expects the ENTIRE object – fields MISSING from the request body get (depending on configuration) reset to their default value. For PARTIAL updates, PATCH is the right tool.
PATCH /api/projects/{id}: partially updating
curl -k -X PATCH https://localhost/api/projects/1 \
-H 'Content-Type: application/merge-patch+json' \
-d '{"description": "Only the description changes"}'Content-Type: application/merge-patch+json (RFC 7396) signals: change ONLY the given fields, leave ALL others UNCHANGED – the DECISIVE difference from PUT.
DELETE /api/projects/{id}: deleting
curl -k -X DELETE https://localhost/api/projects/1Responds with 204 No Content – SUCCESSFUL, but with NO response body, since logically there's NOTHING left to return after a deletion.
Overview: all six standard operations
| HTTP call | Operation |
|---|---|
| GET /projects | Fetch the collection (GetCollection) |
| POST /projects | Create new (Post) |
| GET /projects/{id} | Fetch a single item (Get) |
| PUT /projects/{id} | Fully replace (Put) |
| PATCH /projects/{id} | Partially update (Patch) |
| DELETE /projects/{id} | Delete (Delete) |
Tipp: These SIX operations are API Platform's DEFAULT – chapter 12 shows how to activate ONLY SOME of them (e.g. a read-only resource with no POST/PUT/DELETE), and chapter 61 adds CUSTOM, additional operations beyond these six.