4 min read
ā¢Question 3 of 28easyWhat is the difference between GET and POST?
Understanding GET vs POST HTTP methods.
What You'll Learn
- GET method characteristics
- POST method characteristics
- When to use each
GET vs POST Comparison
| Feature | GET | POST |
|---|---|---|
| Purpose | Retrieve data | Submit data |
| Data location | URL query string | Request body |
| Cacheable | Yes | No |
| Idempotent | Yes | No |
| Bookmarkable | Yes | No |
| Data limit | ~2KB (URL limit) | No limit |
GET Request
code.jsJavaScript
// Fetch users with query params
GET /api/users?page=1&limit=10
// In JavaScript
fetch('/api/users?page=1&limit=10')
.then(res => res.json());POST Request
code.jsJavaScript
// Create new user
POST /api/users
Content-Type: application/json
{ "name": "John", "email": "john@example.com" }
// In JavaScript
fetch('/api/users', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'John', email: 'john@example.com' })
});When to Use
- GET: Fetching data, search queries, filtering
- POST: Creating resources, form submissions, sensitive data