Introduction To Django rest Framework
Django REST Framework (DRF) is a powerful and flexible toolkit for building Web APIs in Python. It is built on top of Django, a popular web framework for Python, and provides many useful features and utilities for creating and testing APIs.
DRF allows developers to quickly and easily build APIs using a wide range of views, serializers, and authentication mechanisms. It also provides a number of built-in tools for handling common tasks such as pagination, filtering, and content negotiation.
Some of the key features of DRF include:
- Support for a wide range of HTTP methods and status codes
- Serialization of complex data types, including nested data and relationships between objects
- Support for multiple authentication schemes, including basic authentication, token-based authentication, and OAuth
- Built-in support for pagination, filtering, and content negotiation
- A browsable API interface for easy testing and exploration of APIs
DRF is widely used in industry and is a popular choice for building RESTful APIs with Python. It is well-documented and has a large and active community of users and contributors.
Django REST framework is a powerful and flexible toolkit for building Web APIs. It allows end-users to access, write, update and delete data using the HTTP methods.
There areFive HTTP methods:
- GET — used to retrieve data
- POST — used to write data
- PUT — used to update data
- PATCH — used to partial update data
- DELETE — used to delete data
Install DRF
1. pip install django_restframework
2.Installing DRF to django project by mentioning it in INSTALLED_APP
INSTALLED_APP=[
'rest_framework',
]
How To Render Api Data In JSON Format
#settings.py
REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
)
}
Or add ?formate=JSON at end of API URL
/api/v1/post/?format=json