Card 09/ 10

ExerciseDifficulty: Intermediate1 min

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.

  1. Read a user's profile.
  2. Rename a project, changing only its name.
  3. Replace a project's settings document with a complete new version.
  4. Add the tag "urgent" to a task's list of tags.
  5. Search all tasks with a filter of thirty conditions, too large for a URL.
  6. Close a user's account.
Show the answers
Each operation, its method, and the two promises
OperationMethod and pathSafeIdempotentWhy
Read a profileGET /users/7YesYesIt only reads
Rename a projectPATCH /projects/3, with the new nameNoYes, as a merge patch that sets a valueA partial change; setting a value twice leaves one name
Replace settingsPUT /projects/3/settingsNoYesThe client sends the whole document
Add a tagPOST /tasks/9/tags, or a JSON Patch addNoNoAdding twice can add twice
Large searchQUERY /tasks, or POST /tasks/search as a fallbackYes with QUERYYes with QUERYA read whose input belongs in a body
Close an accountDELETE /users/7NoYesRemoved 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.