Django Rest Framework
By
Sakthi Panneerselvam
2+ Years of Experience.
Software Engineer @ Tesseract
Learning
LinkedIn - sakthi-panneerselvam
Twitter - sakthipanneer10
What is API ?
● Application Programming Interface.
● API specifies how software components should interact.
● API is set of routines, protocols, and tools for building
software applications.
What is REST ?
● Representational State Transfer.
● REST is a lightweight alternative to mechanisms like RPC
(Remote Procedure Calls) and Web Services (SOAP,
WSDL, etc).
● Restful and Restless Services.
What is DRF ?
Django REST framework is a powerful and flexible toolkit for
building Web APIs.
● The Web browsable API is a huge usability win for your
developers.
● Serialization that supports both ORM and non-ORM data
sources.
Basic Architecture
Serializers
Serializers allow complex data such as querysets and model
instances to be converted to native Python datatypes JSON,
XML and etc.
● ModelSerializers
● HyperlinkedModelSerializer
● ListSerializer
● BaseSerializer
Viewset
Viewset combine the logic for a set of related views in a single class.
● List
● Create
● Retrieve
● Update
● Partial Update
● Destroy
Routers
To avoid creating endless “list”, “detail” and “edit” URLs, the
DRF routers bundle all the URLs needed for a given viewset
into one line per viewset.
● SimpleRouter
● DefaultRouter
Security
Security is managed by Authentication and Permissions.
Authentication schemes are,
● BasicAuthentication - insecure, for testing only
● SessionAuthentication - same session context as website,
powers DRF visualizer
● TokenAuthentication - secure, recommended default!
● RemoteUserAuthentication - intranet sites, rarely used
JSON Web Token
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiV2lsbGlhbS
WaW5jZW50IiwibWVzc2FnZSI6IkhpIERqYW5nb0NvbiEifQ.X5tcGt
N99t8HnjdLvPwDBDbgvU0WuqAS8MKX1Ao7RQ
● eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 - Algorithm & Token type
(HS256)
● eyJuYW1lIjoiV2lsbGlhbSBWaW5jZW50IiwibWVzc2FnZSI6IkhpIER
qYW5nb0NvbiEifQ - Payload (Data)
● X5tcGt3N99t8HnjdLvPwDBDbgvU0WuqAS8MKX1Ao7RQ -
Signature(Secret)
Q & A

Drf

  • 1.
  • 2.
    2+ Years ofExperience. Software Engineer @ Tesseract Learning LinkedIn - sakthi-panneerselvam Twitter - sakthipanneer10
  • 3.
    What is API? ● Application Programming Interface. ● API specifies how software components should interact. ● API is set of routines, protocols, and tools for building software applications.
  • 4.
    What is REST? ● Representational State Transfer. ● REST is a lightweight alternative to mechanisms like RPC (Remote Procedure Calls) and Web Services (SOAP, WSDL, etc). ● Restful and Restless Services.
  • 5.
    What is DRF? Django REST framework is a powerful and flexible toolkit for building Web APIs. ● The Web browsable API is a huge usability win for your developers. ● Serialization that supports both ORM and non-ORM data sources.
  • 6.
  • 7.
    Serializers Serializers allow complexdata such as querysets and model instances to be converted to native Python datatypes JSON, XML and etc. ● ModelSerializers ● HyperlinkedModelSerializer ● ListSerializer ● BaseSerializer
  • 8.
    Viewset Viewset combine thelogic for a set of related views in a single class. ● List ● Create ● Retrieve ● Update ● Partial Update ● Destroy
  • 9.
    Routers To avoid creatingendless “list”, “detail” and “edit” URLs, the DRF routers bundle all the URLs needed for a given viewset into one line per viewset. ● SimpleRouter ● DefaultRouter
  • 10.
    Security Security is managedby Authentication and Permissions. Authentication schemes are, ● BasicAuthentication - insecure, for testing only ● SessionAuthentication - same session context as website, powers DRF visualizer ● TokenAuthentication - secure, recommended default! ● RemoteUserAuthentication - intranet sites, rarely used
  • 11.
    JSON Web Token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiV2lsbGlhbS WaW5jZW50IiwibWVzc2FnZSI6IkhpIERqYW5nb0NvbiEifQ.X5tcGt N99t8HnjdLvPwDBDbgvU0WuqAS8MKX1Ao7RQ ●eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 - Algorithm & Token type (HS256) ● eyJuYW1lIjoiV2lsbGlhbSBWaW5jZW50IiwibWVzc2FnZSI6IkhpIER qYW5nb0NvbiEifQ - Payload (Data) ● X5tcGt3N99t8HnjdLvPwDBDbgvU0WuqAS8MKX1Ao7RQ - Signature(Secret)
  • 12.