Back to All Questions
Question 7 of 100
Basic API Testing
Beginner
Q7: What is the Difference Between GET, POST, PUT, and DELETE?
🔄Core Concept
What is the Difference Between GET, POST, PUT, and DELETE?
Key Takeaways & Architecture Summary
- ✓GET: Safe and idempotent (retrieves data only).
- ✓POST: Non-idempotent (creates a new record on every request).
- ✓PUT: Idempotent (fully replaces resource state, creating it if missing).
- ✓DELETE: Idempotent (removes resource; subsequent calls yield the same state).
Direct Answer Summary
The primary difference lies in resource mutation and idempotency. GET retrieves data without altering server state. POST creates a new resource, appending record instances on duplicate calls. PUT overwrites an existing resource entirely (or creates it if absent). DELETE completely removes the resource. Both GET, PUT, and DELETE are idempotent; POST is not.
⚠️ Senior Engineering Warning (Red Flag)
Avoid calling POST idempotent. If you send the same POST request 5 times, the server will attempt to create 5 distinct user records in the database, whereas 5 identical PUT requests yield only 1 final state.
đź’ˇ STAR Architectural Explanation & Pro Tip
Designing APIs to follow these HTTP principles ensures compatibility with standard HTTP proxies, CDNs, and browser caches, saving resources and preventing runtime issues.
PlaywrightApiTest.ts
Playwright API// Playwright API E2E semantic validation flow
await request.post('/api/users', { data: { name: 'Dev' } }); // Creates resource
await request.put('/api/users/12', { data: { name: 'Dev 2.0' } }); // Overwrites resource
await request.delete('/api/users/12'); // Deletes resource