📬 GET is for Reading. POST is for Writing.
GET caches, shows in URL. POST doesn’t. Choose the right method for security, performance, semantics.
📝 When to Use GET
// ✅ GET: Reading data
await fetch('/api/users');
await fetch('/api/products/123');
await fetch('/api/search?q=keyword');
GET characteristics:
- Idempotent (same request, same result)
- Cachable (browser caches responses)
- Bookmarkable (URL contains all info)
- Limited length (2048 characters)
- Visible in URL (not for sensitive data)
🎯 When to Use POST
// ✅ POST: Writing data
await fetch('/api/users', {
method: 'POST',
body: JSON.stringify(newUser)
});
await fetch('/api/orders', {
method: 'POST',
body: JSON.stringify(order)
});
POST characteristics:
- Not idempotent (multiple POSTs create multiple resources)
- Not cachable by default
- Not bookmarkable
- No length limit
- Data in body (not visible in URL)
- Use for sensitive data
💡 Common Mistake
- ❌ GET for login (password in URL!)
- ❌ GET for delete (browser might pre-fetch and delete!)
- ✅ POST for create, update, delete, login
- ✅ GET for search, list, detail
“Used POST for search queries. Pages couldn’t be bookmarked. Switched to GET. Now users can save search URLs. Choose method based on intent.”
