How to complete the challenge PATCH /api/todos/id (200) partial
Use PATCH with Content-Type: application/json when you want to update selected fields on an existing todo. Partial JSON updates are an API-specific PATCH style.
PATCH /api/todos/id (200) partial
Issue a PATCH request to update an existing todo using a partial JSON payload.
- Use
PATCH /api/todos/{id}where{id}is an existing todo id. - Add
Content-Type: application/json. - Send only the fields you want to change.
- Do not include
idin the payload. - The response should be
200. - Fields that are not in the payload should keep their existing values.
- You can learn more about PATCH in the HTTP verbs tutorial.
Basic Instructions
- Issue a
PATCHrequest to:https://apichallenges.com/api/todos/{{firstTodoId}}
- The request should have an
X-CHALLENGERheader so the challenge is tracked. - The request body can be a partial JSON object:
{
"title": "patched partial todo"
}
Try it now
If you don't know what todos are available then you can check by GET /api/todos. See the solution.
GET /api/todos to see what todos are available now
If you have already deleted all todos, create one using POST /api/todos. See the solution.
POST /api/todos to create a todo item for this challenge
PATCH /api/todos/{id} with partial JSON to update a todo
Example Request
> PATCH /api/todos/3 HTTP/1.1
> Host: apichallenges.com
> User-Agent: rest-client
> X-CHALLENGER: x-challenger-guid
> Content-Type: application/json
> Accept: application/json
>
> {"title":"patched partial todo"}
Example Response
< HTTP/1.1 200 OK
< Content-Type: application/json
< Accept-Patch: application/json, application/merge-patch+json, application/json-patch+json
< X-Challenger: x-challenger-guid
Returned body:
{
"id": 3,
"title": "patched partial todo",
"doneStatus": false,
"description": "existing description"
}
Lessons Learned
- This API accepts
PATCHwith ordinaryapplication/jsonas an API-specific partial update style. - Unlike
PUT, aPATCHbody can focus on the fields being changed. - Partial update tests should prove omitted fields remain unchanged.
Suggested Experiments
- Change only
doneStatus, then fetch the todo and confirmtitleanddescriptionwere preserved. - Send an empty
JSONobject and observe whether the API treats it as no-op or invalid.