RESTFUL API Flashcards
What are the key parts of a RESTFUL API?
1) Response data is represented in JSON format.
2) stateless.
3) use HTTP methods for client-server communications..
4) uses logical URIs to organize resources.
What is REST or RESTFUL API?
A Restful API is a type of software architecture and method for users to request data or information from a server using HTTP methods. We use rest to develop web services. APIs in general are applications that exist to transfer data between application.
What are HTTP methods supported by REST
GET, POST, DELETE, PUT, OPTIONS, HEAD
What are resources in REST architecture?
resources are the logical URLs that represent the location of the piece of data being requested by the client. The resource should contain all the required information.
What do we mean when we say Rest is stateless
REST is stateless therefore the server has no state (or session data).
What is Django rest framework?
DRF is a framework built on Django that allows developers to quickly create restful APIs. We use it in django to create resources that expose our application data per users/service request. services can be browsers, mobile applications, web applications etc.
What are some of the features of DRF?
1) It has a web browsable API
2) It provides authentication and authorization out of the box.
3) Serializer classes that allow you to quickly map your model fields to serializer fields. supports both ORM and non-ORM sources.
4) Easily customizable.
5) Great documentation and user community.
What is a serializer?
A serializer is responsible for transforming objects into JSON. the serializer class defines how attributes on your object should be mapped to serializer fields.
Name a few subclasses of the Serializer class?
from rest_framework import serializers
1) Serializer.
2) ModelSerializer.
3) HyperLinkedModelSerializer.
Describe the ModelSerializer.
The ModelSerializer is a subclass of Serializer. it automatically maps model fields to serializer fields. creates a simple .create( ) and .update( ) methods. and automatically creates validation for your serializer field based on the model validation
what does this serializer attribute return? RandomSerializer(model_instance).data
returns the model instance as python native data-types.
how do you deserialize JSON objects in DRF?
1) RandomSerializer(data=jsondata)
2) RandomSerializer(data=jsondata).is_valid( )
3) RandomSerializer(data-jsondata).validated_data( )
How do we deal with nested objects in DRF?
The Serializer class itself is a type of field and can be used to represent nested relationships. we can do this by simply assigning a field to an instance of a serializer class or subclass.
class CommentSerializer(serializers.Serializer): user = UserSerializer(required=False)
how do you add an extra context to your serializers in DRF?
when we call our Serializer we simply pass the parameter context
ex.
serializer = AccountSerializer(account, context={‘request’: request})
we access the context in our Serializer class with self.context
What is the HyperlinkModelSerializer?
The HyperlinkedModelSerializer class is similar to the ModelSerializer class except that it uses hyperlinks to represent relationships, rather than primary keys.
By default the serializer will include a url field instead of a primary key field.