Django Academy · レッスン

Browsable APIとステータスコード

ブラウザーでエンドポイントを正しくテストします

レッスン 4/413 ステップ

「Browsable APIとステータスコード」はCoddyKit上の無料Django Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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. ✅

無料で開始

AI チューターと学ぶ Python — 無料

ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。

コース
30
レッスン
120

よくある質問

「Browsable APIとステータスコード」レッスンは無料ですか?

はい。「Browsable APIとステータスコード」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Django Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Django Academyコースには全4レッスンが含まれています。

「Browsable APIとステータスコード」で何を学びますか?

ブラウザーでエンドポイントを正しくテストします ブラウザで直接実行するハンズオンコードでDjango Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Django Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのDjango Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「Browsable APIとステータスコード」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このDjango Academyレッスンでコードを書いて実行できますか?

はい。すべてのDjango Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. DRFのインストールと設定
  2. Serializers:ModelからJSONへ
  3. APIViewと関数ベースの@api_view
  4. Browsable APIとステータスコード
← Django Academyに戻る