Card 09/ 10
Practice: Choosing the Method for Six Operations
Read a profile, rename a project, replace a settings document, add a tag, run a big search and close an account.
Choosing the method from what an operation does, and knowing what that choice promises, is what every endpoint needs. For each operation on a project management API, choose the method and path, and say whether the request is safe and whether it is idempotent.
- Read a user's profile.
- Rename a project, changing only its name.
- Replace a project's settings document with a complete new version.
- Add the tag "urgent" to a task's list of tags.
- Search all tasks with a filter of thirty conditions, too large for a URL.
- Close a user's account.
Show the answers
| Operation | Method and path | Safe | Idempotent | Why |
|---|---|---|---|---|
| Read a profile | GET /users/7 | Yes | Yes | It only reads |
| Rename a project | PATCH /projects/3, with the new name | No | Yes, as a merge patch that sets a value | A partial change; setting a value twice leaves one name |
| Replace settings | PUT /projects/3/settings | No | Yes | The client sends the whole document |
| Add a tag | POST /tasks/9/tags, or a JSON Patch add | No | No | Adding twice can add twice |
| Large search | QUERY /tasks, or POST /tasks/search as a fallback | Yes with QUERY | Yes with QUERY | A read whose input belongs in a body |
| Close an account | DELETE /users/7 | No | Yes | Removed once or twice, the account ends up closed |
Closing an account could also be POST /users/7/closure if closing is a process with its own record, such as a cooling-off period. That is still not a GET.
← → move through sections and cards