"Programmatic interface to a defined request-response message system"
Abstract the way data is managed
Standardize data access
Access data from multiple devices
Separate presentation from logic
{
"title": "First Todo",
"completed": "false"
}
<title>First Todo</title>
<completed>false</completed>
Create a new user
from rest_framework import serializers
from task.models import Task
class TaskSerializer( serializers.ModelSerializer ):
"""
Serializer to parse Task data
"""
class Meta:
model = Task
fields = ( 'title', 'completed', 'id' )
class TaskMixin(object):
"""
Mixin to inherit from.
Here we're setting the query set and the serializer
"""
queryset = Task.objects.all()
serializer_class = TaskSerializer
class TaskList(TaskMixin, ListCreateAPIView):
"""
Return a list of all the tasks, or
create new ones
"""
pass
class TaskDetail(TaskMixin, RetrieveUpdateDestroyAPIView):
"""
Return a specific task, update it, or delete it.
"""
pass
CreateAPIView
ListAPIView
RetrieveAPIView
DestroyAPIView
UpdateAPIView
ListCreateAPIView
RetrieveUpdateAPIView
RetrieveDestroyAPIView
RetrieveUpdateDestroyAPIView