PATCH and DELETE Requests #
This section covers using PATCH
requests to update resources and DELETE
requests to remove them, focusing on the Postman Library API.
Updating a Book (Checking Out) #
The PATCH
method allows partial updates to a resource. This example demonstrates updating a book’s checkedOut
status.
- In the Postman Library API v2 collection, add a new request named “checkout a book.”
- Set the request method to
PATCH
. - Set the request URL to
{{baseUrl}}/books/:id
. - In the “Params” tab, set the
id
path variable to{{id}}
(using the collection variable set previously). - In the “Body” tab, select “raw” and “JSON,” then add the following JSON:
{
"checkedOut": true
}
- Save and send the request.
The response should be a 200 OK with the updated book data showing checkedOut: true
. The inherited collection-level authorization applies to this request.
The updated data can also be verified using the “get book by id” request.
Deleting a Book #
The DELETE
method removes a resource. This example demonstrates deleting a book.
- In the Postman Library API v2 collection, add a new request named “delete a book.”
- Set the request method to
DELETE
. - Set the request URL to
{{baseUrl}}/books/:id
. - In the “Params” tab, ensure the
id
path variable is set to{{id}}
. - Save and send the request.
The response should be a 204 No Content, indicating successful deletion.
Verifying Deletion #
Sending the same request again results in a 404 Not Found error because the book with the specified ID no longer exists.