Tan Phat Media

API Tester

Test API endpoints trực tiếp từ trình duyệt

Request
Response

Send a request to see the response

⚠️ Lưu ý về CORS:

Một số API có thể bị chặn bởi CORS policy của trình duyệt. Để test các API này, bạn cần sử dụng Postman hoặc cURL.

API Tester Online - Công cụ Test REST API miễn phí chuyên nghiệp

Công cụ API Tester của Tấn Phát Digital là giải pháp hoàn hảo cho developer cần test REST API endpoints nhanh chóng trực tiếp từ trình duyệt mà không cần cài đặt phần mềm. Hỗ trợ đầy đủ các HTTP methods: GET, POST, PUT, PATCH, DELETE với khả năng tùy chỉnh linh hoạt. Tùy chỉnh headers với giao diện key-value trực quan, JSON body editor với syntax highlighting cho POST/PUT/PATCH requests, hiển thị response body với JSON formatting đẹp mắt, xem response headers chi tiết với tất cả metadata, và đo thời gian response chính xác đến millisecond để đánh giá performance. Giao diện trực quan giống Postman với color-coded status codes giúp nhanh chóng nhận biết success (2xx màu xanh), redirect (3xx màu vàng), client error (4xx màu cam), và server error (5xx màu đỏ). Công cụ hoàn toàn miễn phí, không cần đăng ký tài khoản, xử lý trực tiếp từ browser của bạn với cảnh báo CORS issues kèm hướng dẫn giải quyết chi tiết. Đặc biệt hữu ích cho frontend developers cần test backend APIs, backend developers cần verify endpoints sau deploy, QA engineers cần manual testing, và students học về REST API concepts.

Tính năng nổi bật

Hỗ trợ đầy đủ HTTP methods: GET, POST, PUT, PATCH, DELETE
Custom headers với giao diện key-value dễ sử dụng
JSON body editor cho POST, PUT, PATCH requests
Hiển thị response body với JSON formatting
Xem chi tiết response headers
Color-coded status codes: 2xx xanh, 4xx cam, 5xx đỏ
Đo thời gian response chính xác (milliseconds)
Copy response với một click
Preset Content-Type header mặc định
Cảnh báo CORS issues với hướng dẫn giải quyết

Tại sao developer cần công cụ API Tester?

Trong quá trình phát triển và debug API, developer cần test endpoints thường xuyên để verify functionality, check response format, và debug issues. Postman là công cụ phổ biến nhưng cần cài đặt và có thể nặng cho các quick tests. API Tester online cho phép test ngay trên browser, không cần cài đặt, tiện lợi khi làm việc trên máy khác hoặc cần share test với team. Công cụ đặc biệt hữu ích cho việc quick debugging, verify API sau deploy, demo API cho stakeholders, và học tập về REST API cho beginners.

Lợi ích khi sử dụng

  • Test API ngay trên browser, không cần cài đặt phần mềm
  • Tiện lợi cho quick debugging và verification
  • Giao diện đơn giản, dễ sử dụng hơn Postman cho basic tests
  • Xem response time để đánh giá performance
  • Color-coded status giúp nhanh chóng nhận biết kết quả
  • Học tập REST API concepts cho beginners
  • Share test results dễ dàng qua screenshot
  • Hoàn toàn miễn phí, không giới hạn requests

Hướng dẫn chi tiết cách test API online

  1. 1Chọn HTTP method từ dropdown: GET, POST, PUT, PATCH, hoặc DELETE
  2. 2Nhập URL endpoint đầy đủ (bao gồm https://)
  3. 3Thêm headers nếu cần: Authorization, API keys, custom headers
  4. 4Với POST/PUT/PATCH, nhập JSON body trong textarea
  5. 5Click 'Send Request' để gửi request
  6. 6Xem status code và response time
  7. 7Kiểm tra response headers và body
  8. 8Copy response nếu cần sử dụng

Hiểu về HTTP Status Codes chi tiết và ý nghĩa

Status codes là mã số 3 chữ số cho biết kết quả của HTTP request, được chia thành 5 nhóm chính theo RFC 7231. 1xx (Informational): 100 Continue - server đã nhận headers, client có thể tiếp tục gửi body; 101 Switching Protocols - server đồng ý chuyển protocol (thường dùng cho WebSocket upgrade). 2xx (Success): 200 OK - request thành công với response body; 201 Created - resource mới được tạo thành công, thường trả về trong POST requests; 202 Accepted - request được chấp nhận nhưng chưa xử lý xong (async processing); 204 No Content - thành công nhưng không có response body, thường dùng cho DELETE. 3xx (Redirect): 301 Moved Permanently - resource đã chuyển vĩnh viễn, browsers cache redirect này; 302 Found - redirect tạm thời; 304 Not Modified - resource không thay đổi, dùng cached version. 4xx (Client Error): 400 Bad Request - request syntax không hợp lệ hoặc thiếu required fields; 401 Unauthorized - cần authentication, thường thiếu hoặc sai token; 403 Forbidden - authenticated nhưng không có quyền access resource; 404 Not Found - resource không tồn tại; 405 Method Not Allowed - HTTP method không được hỗ trợ cho endpoint này; 409 Conflict - conflict với current state của resource; 422 Unprocessable Entity - validation errors; 429 Too Many Requests - rate limiting. 5xx (Server Error): 500 Internal Server Error - lỗi server không xác định; 502 Bad Gateway - proxy/gateway nhận invalid response từ upstream server; 503 Service Unavailable - server quá tải hoặc đang maintenance; 504 Gateway Timeout - proxy/gateway không nhận được response kịp thời.

Giải quyết vấn đề CORS khi test API từ browser

CORS (Cross-Origin Resource Sharing) là cơ chế bảo mật quan trọng của browser, ngăn chặn requests từ domain khác (cross-origin) trừ khi server explicitly cho phép thông qua HTTP headers. Đây là protection chống CSRF (Cross-Site Request Forgery) attacks và data theft. Khi browser gửi cross-origin request, nó thực hiện preflight request (OPTIONS method) để check server có cho phép không. Server cần trả về headers: Access-Control-Allow-Origin (domain được phép hoặc * cho tất cả), Access-Control-Allow-Methods (GET, POST, PUT, DELETE...), Access-Control-Allow-Headers (Content-Type, Authorization...). Khi gặp CORS error trong công cụ này, có nhiều giải pháp: 1) Yêu cầu backend team thêm CORS headers cho domain của bạn - đây là giải pháp đúng nhất. 2) Sử dụng Postman desktop app hoặc cURL command line - những tools này không chạy trong browser nên không bị CORS policy. 3) Tạo backend proxy server để forward requests - proxy chạy server-side nên bypass CORS. 4) Sử dụng browser extension như 'CORS Unblock' để disable CORS - CHỈ dùng cho development, KHÔNG bao giờ dùng cho production vì compromise security. 5) Test trên localhost nếu API cho phép localhost trong CORS config. 6) Sử dụng CORS proxy services như cors-anywhere (cẩn thận với sensitive data). Lưu ý: CORS không phải bug mà là security feature, giải pháp đúng là configure server properly thay vì bypass.

HTTP Methods và RESTful API conventions

REST (Representational State Transfer) là architectural style cho web APIs, sử dụng HTTP methods để thực hiện CRUD operations trên resources. GET - Retrieve/đọc data, không thay đổi server state (idempotent và safe), có thể cache, parameters trong URL query string. Ví dụ: GET /api/users để lấy danh sách users, GET /api/users/123 để lấy user cụ thể. POST - Create/tạo mới resource, thay đổi server state, không idempotent (gọi nhiều lần tạo nhiều resources), body chứa data của resource mới. Ví dụ: POST /api/users với body {name: 'John', email: 'john@example.com'}. PUT - Update/replace toàn bộ resource, idempotent (gọi nhiều lần kết quả giống nhau), body chứa complete resource data. Ví dụ: PUT /api/users/123 với full user object. PATCH - Partial update, chỉ update fields được gửi trong body, idempotent. Ví dụ: PATCH /api/users/123 với {email: 'newemail@example.com'} chỉ update email. DELETE - Remove resource, idempotent, thường không có body. Ví dụ: DELETE /api/users/123. HEAD - Giống GET nhưng chỉ trả về headers, không có body, dùng để check resource existence hoặc metadata. OPTIONS - Trả về supported methods cho endpoint, dùng trong CORS preflight. Best practices: Sử dụng nouns cho resource names (/users, /products), plural forms, nested resources cho relationships (/users/123/orders), versioning trong URL (/api/v1/users) hoặc header.

Authentication và Authorization trong API testing

Authentication (xác thực) verify identity của user/client, Authorization (phân quyền) determine những gì user được phép làm. Các phương thức authentication phổ biến: API Key - Simple key string gửi trong header (X-API-Key: your-key) hoặc query parameter (?api_key=your-key). Dễ implement nhưng ít secure, phù hợp cho public APIs với rate limiting. Basic Auth - Username:password encoded base64 trong Authorization header: 'Basic dXNlcm5hbWU6cGFzc3dvcmQ='. Simple nhưng credentials gửi mỗi request, cần HTTPS. Bearer Token/JWT - Token gửi trong Authorization header: 'Bearer eyJhbGciOiJIUzI1NiIs...'. JWT (JSON Web Token) chứa encoded user info và signature, stateless, có expiration. Phổ biến nhất cho modern APIs. OAuth 2.0 - Authorization framework cho third-party access, có nhiều flows: Authorization Code (web apps), Client Credentials (server-to-server), Implicit (deprecated), PKCE (mobile/SPA). Trả về access_token và optional refresh_token. Session/Cookie - Server tạo session, gửi session ID trong cookie. Stateful, cần server storage. Khi test API với authentication: 1) Đọc API documentation để biết auth method. 2) Obtain credentials/tokens (register, login, hoặc generate API key). 3) Thêm appropriate header trong request. 4) Handle token expiration và refresh. 5) Test với invalid/expired tokens để verify error handling.

Best practices cho API testing và debugging

Systematic approach: Bắt đầu với happy path (valid inputs, expected responses), sau đó test edge cases và error scenarios. Document test cases và expected results. Environment management: Sử dụng different base URLs cho development, staging, production. Không hardcode credentials, sử dụng environment variables. Request validation: Verify request format trước khi gửi - check JSON syntax, required fields, data types. Sử dụng JSON validators. Response validation: Check status code, response time, response body structure, data types, và business logic. Compare với API documentation. Error handling: Test với invalid inputs, missing required fields, wrong data types, unauthorized access, rate limiting. Verify error messages helpful và không leak sensitive info. Performance testing: Monitor response times, test với large payloads, concurrent requests. Identify bottlenecks. Security testing: Test authentication bypass, injection attacks, sensitive data exposure. Verify HTTPS, proper error messages. Documentation: Keep track of tested endpoints, test cases, issues found. Share với team. Automation: Cho repetitive tests, consider tools như Postman Collections, Newman, hoặc code-based testing với Jest/Mocha. Version control: Track API changes, test backward compatibility. Collaboration: Share test results, discuss issues với backend team, maintain communication.

Câu hỏi thường gặp (FAQ)

CORS là gì và tại sao request bị chặn khi test API từ browser?

CORS (Cross-Origin Resource Sharing) là cơ chế bảo mật quan trọng của browser, ngăn website gọi API từ domain khác (cross-origin) trừ khi server explicitly cho phép thông qua HTTP headers. Đây là protection chống CSRF (Cross-Site Request Forgery) attacks và data theft. Khi bạn test API từ domain A (ví dụ: tanphatdigital.com) gọi đến API ở domain B (ví dụ: api.example.com), browser sẽ check xem server B có cho phép domain A không. Server cần trả về header 'Access-Control-Allow-Origin: https://tanphatdigital.com' hoặc 'Access-Control-Allow-Origin: *' (cho phép tất cả). Nếu không có header này, browser block response và bạn thấy CORS error. Lưu ý: CORS chỉ áp dụng cho browser-based requests, không ảnh hưởng đến server-to-server calls, Postman, hoặc cURL.

Làm sao test API bị CORS block? Có cách nào bypass không?

Có nhiều cách để test API bị CORS block: 1) Sử dụng Postman desktop app - không chạy trong browser nên không bị CORS. 2) Sử dụng cURL command line: curl -X GET 'https://api.example.com/data' -H 'Authorization: Bearer token'. 3) Tạo backend proxy server để forward requests - proxy chạy server-side bypass CORS. 4) Yêu cầu backend team thêm CORS headers cho domain của bạn hoặc localhost cho development. 5) Sử dụng browser extension như 'CORS Unblock' - CHỈ cho development, disable ngay sau khi test xong vì compromise security. 6) Test trên localhost nếu API whitelist localhost. Giải pháp đúng nhất là configure server properly với appropriate CORS headers thay vì bypass security.

Authorization header dùng như thế nào? Có những loại authentication nào?

Authorization header gửi credentials để authenticate với API. Các loại phổ biến: 1) Bearer Token/JWT: Header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIs...' - phổ biến nhất cho modern APIs, token có expiration. 2) Basic Auth: Header 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=' - username:password encoded base64, cần HTTPS. 3) API Key: Có thể trong header 'X-API-Key: your-api-key' hoặc query param '?api_key=your-key'. 4) OAuth 2.0: Sử dụng access_token từ OAuth flow trong Bearer header. Đọc API documentation để biết auth method cụ thể. Trong công cụ này, thêm header với key 'Authorization' và value theo format tương ứng.

Tại sao response time quan trọng? Bao nhiêu ms là acceptable?

Response time cho biết performance của API và ảnh hưởng trực tiếp đến user experience. Guidelines: Dưới 100ms - Excellent, users perceive as instant. 100-200ms - Good, acceptable cho hầu hết use cases. 200-500ms - Acceptable, nhưng có thể improve. 500ms-1s - Slow, cần investigate và optimize. Trên 1s - Poor, definitely cần optimize. Factors ảnh hưởng response time: Network latency (distance to server, internet speed), server processing time (code efficiency, algorithms), database queries (query optimization, indexing), payload size (response data amount), server load (concurrent requests), caching (có cache hay không). Để improve: Optimize database queries, implement caching, reduce payload size, use CDN, scale server resources.

Có thể test WebSocket, GraphQL, hoặc gRPC không?

Công cụ này chuyên cho REST API (HTTP/HTTPS requests). Cho các protocols khác: WebSocket - Sử dụng Postman WebSocket feature, browser DevTools Console, hoặc wscat command line tool. GraphQL - Có thể test qua POST request với query trong body, nhưng recommend GraphQL Playground, Apollo Studio, hoặc Insomnia với GraphQL support. gRPC - Cần tools chuyên biệt như BloomRPC, grpcurl, hoặc Postman gRPC feature. Mỗi protocol có characteristics riêng và cần tools phù hợp để test effectively.

Request có được lưu lại không? Làm sao save và reuse requests?

Không, công cụ này không lưu requests - mỗi lần refresh trang sẽ reset tất cả. Đây là design choice để đảm bảo privacy và simplicity. Nếu cần lưu và organize requests: 1) Postman - Collections feature cho phép save, organize, và share requests. Có thể export/import collections. 2) Insomnia - Tương tự Postman với workspace và request organization. 3) Thunder Client (VS Code extension) - Lightweight API client trong editor. 4) Manually save requests trong text file hoặc documentation. 5) Sử dụng cURL commands trong shell scripts để automate và version control. Cho team collaboration, Postman Teams hoặc Insomnia Sync cho phép share collections.

Làm sao test API với file upload (multipart/form-data)?

Công cụ này hiện tại focus vào JSON APIs. Cho file upload với multipart/form-data: 1) Postman - Có UI để select files và build multipart requests. 2) cURL: curl -X POST -F 'file=@/path/to/file.jpg' -F 'name=test' https://api.example.com/upload. 3) Browser DevTools - Sử dụng fetch() trong Console với FormData object. 4) Insomnia - Support multipart form data với file picker. File uploads thường cần different Content-Type header (multipart/form-data thay vì application/json) và body format khác.

API trả về 401 Unauthorized, làm sao fix?

401 Unauthorized nghĩa là authentication failed - server không recognize credentials của bạn. Troubleshooting steps: 1) Check Authorization header có đúng format không (Bearer token, Basic auth, API key). 2) Verify token/credentials còn valid và chưa expired. 3) Đảm bảo không có typo trong token hoặc API key. 4) Check API documentation xem auth method có đúng không. 5) Nếu dùng JWT, verify token chưa expired (decode tại jwt.io để check exp claim). 6) Thử generate new token/credentials. 7) Check xem API có require specific scopes/permissions không. 8) Contact API provider nếu vẫn không được. Khác với 403 Forbidden - 401 là 'who are you?', 403 là 'I know who you are but you cannot access this'.

Từ khóa liên quan

api tester onlinetest rest apipostman alternativehttp request testerapi debugging toolrest client onlinetest api endpointjson api testerweb api testerapi testing free

Hợp tác ngay với Tấn Phát Digital

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.

Zalo
Facebook
Tấn Phát Digital
Zalo
Facebook