0Pricing
Django Academy · บทเรียน

API ที่เรียกดูได้และรหัสสถานะ

ทดสอบเอนด์พอยต์ในเบราว์เซอร์อย่างถูกต้อง

API ที่เรียกดูได้และรหัสสถานะ เป็นบทเรียน Django Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Django Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Django Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Test in the Browser

DRF's browsable API renders any endpoint as an interactive web page, so you can explore and test your API without extra tools. 🌐

How It Decides

DRF uses content negotiation: browsers ask for HTML and get the friendly page, while code asking for JSON gets raw JSON instead.

Forms for Free

For write endpoints the browsable API even shows a form, letting you POST test data with a click instead of crafting curl commands.

Force JSON Anytime

Append ?format=json to any URL to skip the HTML page and see the exact JSON a real client would receive.

GET /api/books/?format=json

Status Codes Matter

Every API response carries an HTTP status code that tells the client what happened, far more reliably than reading the body text.

200 and 201

200 means a successful read, while 201 Created signals that a POST actually made a new resource, a small but important distinction.

Readable Constants

Instead of magic numbers, DRF gives you named constants in status so your code reads clearly and avoids typos like 20 versus 200.

from rest_framework import status
status.HTTP_201_CREATED

Client Errors: 400 and 404

The 4xx range blames the request: 400 means bad input that failed validation, and 404 means the resource simply was not found.

Response(serializer.errors, status=400)

Server Errors: 500

A 500 means your code crashed, not the client. These signal bugs to fix, never something the caller did wrong.

Match Code to Outcome

Good APIs are predictable: return 201 on create, 400 on invalid input, 404 when missing. Correct status codes make clients trust you.

Browsable Plus Status

Together the browsable API and clear status codes make DRF endpoints easy to test by hand and easy for clients to consume.

Quick Check

Which status code best fits a successful POST that creates a record?

Recap: Test and Respond

You met the browsable API for hands-on testing and learned to return honest status codes like 200, 201, 400, and 404. ✅

คำถามที่พบบ่อย

บทเรียน “API ที่เรียกดูได้และรหัสสถานะ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “API ที่เรียกดูได้และรหัสสถานะ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Django Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Django Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “API ที่เรียกดูได้และรหัสสถานะ”

ทดสอบเอนด์พอยต์ในเบราว์เซอร์อย่างถูกต้อง คุณปฏิบัติ Django Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Django Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Django Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “API ที่เรียกดูได้และรหัสสถานะ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Django Academy นี้ได้ไหม

ได้ บทเรียน Django Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การติดตั้งและกำหนดค่า DRF
  2. ซีเรียลไลเซอร์: โมเดลเป็น JSON
  3. APIView และฟังก์ชัน @api_view
  4. API ที่เรียกดูได้และรหัสสถานะ
← กลับไปที่ Django Academy