RESTFUL API Flashcards

1
Q

What are the key parts of a RESTFUL API?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is REST or RESTFUL API?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are HTTP methods supported by REST

A

GET, POST, DELETE, PUT, OPTIONS, HEAD

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are resources in REST architecture?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What do we mean when we say Rest is stateless

A

REST is stateless therefore the server has no state (or session data).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Django rest framework?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are some of the features of DRF?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a serializer?

A

A serializer is responsible for transforming objects into JSON. the serializer class defines how attributes on your object should be mapped to serializer fields.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Name a few subclasses of the Serializer class?

A

from rest_framework import serializers

1) Serializer.
2) ModelSerializer.
3) HyperLinkedModelSerializer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Describe the ModelSerializer.

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what does this serializer attribute return? RandomSerializer(model_instance).data

A

returns the model instance as python native data-types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

how do you deserialize JSON objects in DRF?

A

1) RandomSerializer(data=jsondata)
2) RandomSerializer(data=jsondata).is_valid( )
3) RandomSerializer(data-jsondata).validated_data( )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do we deal with nested objects in DRF?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

how do you add an extra context to your serializers in DRF?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the HyperlinkModelSerializer?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

how are permissions determined in DRF?

A

Permissions are determined by a list of permission classes. one i’m familiar with is DjangoModelPermissionsOrAnonReadOnly. just like DjangoModelPermissions except it allows unauthenticated users Read only access to the API.

17
Q

what happens if a permission check in DRF fails?

A

When the permissions checks fail either a “403 Forbidden” or a “401 Unauthorized” response will be returned

18
Q

what is ReadOnlyViewSet in DRF?

A

The ReadOnlyModelViewSet class also inherits from GenericAPIView. As with ModelViewSet it also includes implementations for various actions, but unlike ModelViewSet only provides the ‘read-only’ actions, .list() and .retrieve().

19
Q

What are some best practices when it comes to DRF.

A

1) API should be readable, and web browsable.
2) Intuitive and provides good documentation.
3) Always use SSL.
4) Provide versioning.
5) Filtering and search where appropriate.
6) Return only what’s needed.
7) Must return JSON.
8) gzip.
9) Provide pagination support.

20
Q

Describe DRFs workflow.

A

The Django ORM generates and handles DB models and queries. DRF Serializes data from the Django ORM and permits access.

21
Q

What does it mean for an HTTP method to be “safe”?

A

An HTTP method is safe if it doesn’t alter the state of the server. In other words, a method is safe if it leads to a read-only operation. ex: GET, OPTIONS, HEAD

unsafe method ex: PUT & DELETE