HTTP verb: PATCH
This course covers the HTTP PATCH method, which applies partial modifications to a resource. It compares PATCH with PUT and shows how a PATCH request body carries only the fields that change. It explains why PATCH is classified as non-idempotent and how conditional requests with If-Match and ETags prevent lost updates. It presents the JSON Patch and JSON Merge Patch standards, the status codes a server returns after a PATCH, and how Ruby on Rails routes and handles PATCH updates.
What you'll learn
- ✓How PATCH differs from PUT: partial modification versus full replacement
- ✓How to structure a patch document and choose its Content-Type
- ✓Why PATCH is not idempotent and how If-Match prevents conflicting updates
- ✓How JSON Patch operations and JSON Merge Patch rules work
- ✓Which success and error status codes a PATCH response uses
- ✓How Rails routes PATCH and PUT to the update action
What is the PATCH method?
The PATCH method is an HTTP verb used to apply partial modifications to a resource.
Read the full lesson free →Curriculum
7 lessonsWhat is the PATCH method?
Defines PATCH as a partial update, contrasts it with PUT, and covers its efficiency and adoption.
Anatomy of a PATCH request
Shows a PATCH request whose body is a small patch document containing only the fields being changed.
PATCH vs PUT
Explains when to use PUT or PATCH, and how If-Match with an ETag prevents overwriting concurrent edits.
Idempotency and PATCH
Shows why PATCH is classified as non-idempotent, using an increment operation that changes state on every request.
The JSON patch standard
Covers JSON Patch operations and paths, plus the simpler JSON Merge Patch and its null removal rule.
The response of a PATCH request
Describes 200 and 204 success responses and the common error codes 400, 404, 409, 415 and 422.
PATCH requests in Rails
Explains why Rails routes both PATCH and PUT to update and made PATCH the default from Rails 4.0.