Beginner LevelREST APIs & Web Services
What are HTTP Verbs (GET, POST, PUT, PATCH, DELETE) and when to use PUT vs PATCH?
❓ Interview Prompt: Compare HTTP CRUD operations and explain the fundamental resource replacement difference between PUT and PATCH.
HTTP Verbs define the intent of an API operation:
•
'GET': Retrieve resources (Safe & Idempotent). Should never mutate server state.
•
'POST': Create a new child resource under a collection (Non-Idempotent).
•
'PUT': Replace an existing resource completely (Idempotent). Unsupplied fields are reset to default/null!
•
'PATCH': Apply partial updates to specific fields of an existing resource (Idempotent or Non-Idempotent).
•
'DELETE': Remove a resource by ID (Idempotent).
Code Implementation Example
json
// PUT /api/v1/users/42 (Replaces ENTIRE user object)
// If 'role' is omitted, PUT resets role to null!
{ "firstName": "Alice", "lastName": "Smith" }
// PATCH /api/v1/users/42 (Modifies ONLY specified field)
{ "lastName": "Smith" }💡Comparing complete resource replacement with PUT vs partial modification with PATCH.
🎯 Interview Key Takeaway
Use PUT for complete resource replacements and PATCH for partial resource updates.
#HTTP Verbs#PUT vs PATCH#REST API#Beginner
Back to all REST APIs & Web Services Questions→