Fundamentos de Django Rest Framework
Crea y escala APIs con Django REST Framework
Introducci贸n a las APIs, REST y JSON
Instalaci贸n de Django y Django REST Framework
Integraci贸n de Django REST Framework en proyectos Django
C贸mo crear modelos y serializadores en Django REST Framework
Implementar vistas basadas en funciones en Django REST Framework
Gesti贸n de Vistas Basadas en Funciones en Django REST Framework
驴C贸mo modificar y eliminar recursos con Django REST Framework?
Postman y cURL en Django REST Framework
Refactorizar las funciones a clases en Django REST Framework
Refactorizando vistas en Django REST Framework con vistas gen茅ricas
Documentaci贸n de APIs con Django REST, Swagger y OpenAPI
Vistas y Endpoints
Vistas Personalizadas y ViewSets en Django REST Framework
Manejos de Acciones con ViewSet en Django REST Framework
Autenticaci贸n y Gesti贸n de Roles en Django REST Framework
Manejo de Errores y Validaciones
Serializadores Avanzados
驴C贸mo implementar serializadores anidados en Django Django REST Framework?
驴C贸mo usar SerializerMethodField en Django REST Framework?
Endpoint Anidado para Appointments Usando @action
Testing y Desempe帽o
Pruebas Unitarias para Endpoints Anidados Usando APIClient
Throttling en Django REST Framework
You don't have access to this class
Keep learning! Join and start boosting your career
The implementation of endpoints in Django REST Framework allows us to work with resources as patients, both to list them and to create them, using the appropriate HTTP methods. The next step will be to extend these functionalities to modify and delete records.
To allow both the creation and reading of patients on a single endpoint, we use GET and POST methods. GET takes care of listing patients, while POST creates a new one. To achieve this:
request.method.
save()
method is used to save the new patient in the database.In case the data sent is invalid, Django REST Framework catches the errors and formats them into a JSON response. This is done with raise_exception=True
in the serializer, which automatically returns a response with the error details without the need for a conditional.
Once the patient is successfully created, the server responds with an HTTP 201 status code, indicating that the resource was created. This is done with Response(status=status.HTTP_201_CREATED)
, ensuring that the client receives the appropriate confirmation.
To get the detail of a specific patient, you use the GET method on an endpoint that includes a URL parameter, usually the patient ID:
get_object_or_404()
.The PUT method allows you to modify an existing patient. It uses the same logic as GET to obtain the patient, but instead of returning the data, it updates the information received:
Contributions 12
Questions 1
Want to see more contributions, questions and answers from the community?