A API navegável e códigos de status
Teste endpoints corretamente no navegador
A API navegável e códigos de status é uma aula grátis de Django Academy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Django Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Django Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
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=jsonStatus 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_CREATEDClient 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. ✅
Perguntas Frequentes
A aula “A API navegável e códigos de status” é grátis?
Sim — o texto completo de “A API navegável e códigos de status” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Django Academy, atualize para CoddyKit PRO. O curso de Django Academy inclui 4 aulas no total.
O que vou aprender em “A API navegável e códigos de status”?
Teste endpoints corretamente no navegador Você pratica Django Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Django Academy?
Nenhuma experiência prévia é necessária. Django Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “A API navegável e códigos de status”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Django Academy?
Sim. Cada aula de Django Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Instalando e configurando DRF
- Serializadores: modelo para JSON
- APIView e função @api_view
- A API navegável e códigos de status