Tra cứu đầy đủ các HTTP methods với ví dụ và best practices
Retrieve data from server. Should only retrieve data and have no other effect.
Fetching resources, reading data, search queries
GET /api/users/123 HTTP/1.1
Host: api.example.com
Accept: application/jsonSubmit data to server to create a new resource. Often causes state change or side effects.
Creating resources, submitting forms, uploading files
POST /api/users HTTP/1.1
Host: api.example.com
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com"
}Replace all current representations of target resource with request payload.
Updating entire resource, replacing data
PUT /api/users/123 HTTP/1.1
Host: api.example.com
Content-Type: application/json
{
"name": "John Smith",
"email": "john.smith@example.com"
}Apply partial modifications to a resource.
Partial updates, modifying specific fields
PATCH /api/users/123 HTTP/1.1
Host: api.example.com
Content-Type: application/json
{
"email": "newemail@example.com"
}Delete the specified resource.
Removing resources, deleting data
DELETE /api/users/123 HTTP/1.1
Host: api.example.comSame as GET but returns only headers, no body. Used to check if resource exists.
Checking resource existence, getting metadata
HEAD /api/users/123 HTTP/1.1
Host: api.example.comDescribe communication options for target resource. Used for CORS preflight.
CORS preflight, discovering allowed methods
OPTIONS /api/users HTTP/1.1
Host: api.example.com
Access-Control-Request-Method: POSTHTTP Method Reference là bảng tra cứu đầy đủ các HTTP methods (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS) với hướng dẫn sử dụng, ví dụ code, status codes và best practices cho RESTful API development.
HTTP methods là foundation của RESTful APIs và web communication. Hiểu rõ từng method, khi nào dùng GET vs POST, PUT vs PATCH, và properties như idempotent, safe, cacheable là essential cho API design. HTTP Method Reference giúp developers tra cứu nhanh, học best practices, và implement APIs đúng chuẩn. Đặc biệt hữu ích khi design RESTful APIs, debug HTTP requests, hoặc học web development.
Safe methods (GET, HEAD, OPTIONS) không thay đổi server state, chỉ retrieve data. Idempotent methods (GET, PUT, DELETE, HEAD, OPTIONS) cho kết quả giống nhau dù gọi 1 lần hay nhiều lần. POST và PATCH không idempotent vì mỗi request có thể tạo resource mới hoặc thay đổi state khác nhau. Hiểu properties này quan trọng cho retry logic và API design.
Khi design RESTful APIs: dùng GET cho reading, POST cho creating, PUT cho full updates, PATCH cho partial updates, DELETE cho removing. Use proper status codes: 2xx cho success, 4xx cho client errors, 5xx cho server errors. Implement proper error handling, versioning, authentication, và rate limiting. Follow naming conventions: plural nouns cho resources (/users, /posts), avoid verbs trong URLs.
Browser gửi OPTIONS preflight request trước actual request khi: cross-origin request, custom headers, hoặc methods khác GET/POST. Server phải respond với proper CORS headers: Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Headers. Preflight responses có thể được cached với Access-Control-Max-Age. Hiểu CORS quan trọng cho frontend-backend communication.
GET dùng để retrieve data, parameters trong URL, idempotent và safe, có thể cached. POST dùng để create resources, data trong request body, không idempotent, không cached. GET cho reading, POST cho creating/submitting data.
PUT replace toàn bộ resource, phải gửi full data. PATCH chỉ update một phần, gửi fields cần thay đổi. Ví dụ: PUT /users/1 với full user object, PATCH /users/1 chỉ với {email: 'new@email.com'}. PATCH tiết kiệm bandwidth hơn.
Idempotent method cho kết quả giống nhau dù gọi 1 lần hay nhiều lần. GET, PUT, DELETE, HEAD, OPTIONS là idempotent. POST không idempotent vì mỗi request có thể tạo resource mới. Idempotency quan trọng cho retry logic và reliability.
HEAD giống GET nhưng chỉ trả về headers, không có body. Dùng để check resource existence, get metadata (size, last-modified), hoặc validate cache mà không download full content. Tiết kiệm bandwidth khi chỉ cần metadata.
OPTIONS dùng để discover allowed methods cho resource và handle CORS preflight requests. Browser tự động gửi OPTIONS trước cross-origin requests. Server respond với Access-Control-Allow-Methods header listing allowed methods.
Theo HTTP spec, POST responses không cacheable by default trừ khi có explicit Cache-Control hoặc Expires headers. Trong thực tế, POST thường không được cached vì tạo side effects. GET và HEAD là cacheable by default.
Có, DELETE là idempotent. Gọi DELETE /users/1 nhiều lần cho kết quả giống nhau: resource bị xóa. Lần đầu return 200/204, lần sau có thể return 404, nhưng end state giống nhau (resource không tồn tại).
201 Created khi tạo resource mới (nên include Location header với URL của resource). 200 OK khi POST không tạo resource mới nhưng process thành công. 204 No Content khi success nhưng không có data trả về.
Chúng tôi không chỉ thiết kế website, mà còn giúp doanh nghiệp xây dựng thương hiệu số mạnh mẽ. Cung cấp dịch vụ thiết kế website trọn gói từ thiết kế đến tối ưu SEO. Hãy liên hệ ngay với Tấn Phát Digital để cùng tạo nên những giải pháp công nghệ đột phá, hiệu quả và bền vững cho doanh nghiệp của bạn tại Hồ Chí Minh.
Tạo file .env và .env.example cho dự án.
Tạo .gitignore cho Node.js, Python, Java.
Tạo mock JSON data cho API testing.
Format và phân tích API response.
Test REST API: GET, POST, PUT, DELETE.
Chuyển đổi Binary, Hex, Base32.
Mã hóa/giải mã Base64.
Chuyển đổi Decimal, Binary, Hex.
Tạo CSS box-shadow trực quan.
Tính quyền file Linux.
Kiểm tra WCAG accessibility.
Tạo bảng màu ngẫu nhiên.