Package: django-pds
Info:Faster REST API development using Django and mongodbRepository:https://github.com/knroy/django-pdspds stands for platform data service. you need to create rest api faster? just a few configuration and let's go? django-pds is here to help.django-pds:: Faster REST API development using Django and mongodb with row level security and out of the box built in frontend query support.django-pdsprovides few sophisticated methods, configurable to create REST API with Django and MongoDB faster.quick startInstall:pipinstalldjango_pdsCreate new app:pythonmanage.pystartappapiAdddjango-pdsandapiapp inINSTALLED_APPSinsettings. As we are going to use rest api,rest_frameworkandcorsheadersapps are needed too.django_pdsbuilt on top ofMongoEngineandDjango. When you useMongoEngine, admin is not supported directly. So, the basic structure ofINSTALLED_APPSlist is like below,INSTALLED_APPS=['rest_framework','django.contrib.staticfiles','corsheaders','django_pds','api']djangosettingsfile will be looking like the following code:.....importmongoengine......ALLOWED_HOSTS=['*']REST_FRAMEWORK={'UNAUTHENTICATED_USER':None}INSTALLED_APPS=['rest_framework','django.contrib.staticfiles','corsheaders','django_pds','api']MIDDLEWARE=['corsheaders.middleware.CorsMiddleware','django.middleware.common.CommonMiddleware']CORS_ORIGIN_ALLOW_ALL=TrueCORS_ALLOW_METHODS=('DELETE','GET','OPTIONS','PATCH','POST','PUT',)...............DATABASES={}# mongodb connectionMONGODB_DATABASE_NAME='django_pds_db'mongoengine.connect(MONGODB_DATABASE_NAME)..........defining document schema:frommongoengineimport*fromdjango_pds.core.baseimportSimpleBaseDocumentclassPage(SimpleBaseDocument):title=StringField(max_length=200,required=True)tags=ListField(StringField(required=True),required=True)Create Insert Rest API:create a class namedRestInsertinapiappviews.pyfileimportjsonfromuuidimportuuid4fromrest_frameworkimportstatusfromrest_framework.responseimportResponsefromdjango_pds.core.pds.genericimportdata_insertfromdjango_pds.core.rest.responseimporterror_response,success_responsefromdjango_pds.core.rest.viewsimportBaseAPIViewclassRestInsert(BaseAPIView):defpost(self):try:document_name='Page'data={"ItemId":str(uuid4()),"title":"Using django-pds","tags":["django","django-pds","mongoengine"]}# as we are not checking row level security,# ignoring offered row level securityerror,result=data_insert(document_name,data,ignore_security=True)iferror:response=error_response(result)returnResponse(response,status=status.HTTP_400_BAD_REQUEST)response=success_response(result)returnResponse(response,status=status.HTTP_400_BAD_REQUEST)exceptBaseExceptionase:response=error_response(str(e))returnResponse(response,status=status.HTTP_400_BAD_REQUEST)add the view inapi.urls.py:fromdjango.urlsimportre_pathfrom.viewsimportRestInserturlpatterns=[re_path(r'^insert$',RestInsert.as_view(),name='rest api insert'),]and add rest api app in the appapp_name.urls:fromdjango.urlsimportinclude,re_pathurlpatterns=[re_path(r'^rest_api/',include('api.urls'))]how to make it dynamic? How to send data with request or from frontend and collect them in the API from the request and insert into the database?we need to change theRestInsertAPI View a little bit, here it goes:fromdjango_pds.core.rest.decoratorsimportrequired....classRestInsert(BaseAPIView):# required decorator check request.data# before calling the post method for these required params@required("document_name","data")defpost(self,request):try:# we are expecting payload with the requestdocument_name=request.data['document_name']data=request.data['data']# as we are not checking row level security,# ignoring offered row level security.....and to request to this REST API endpoint, usepostmanorcurl.curl request:curl --header "Content-Type: application/json" \
  --request POST \
  --data '{
	"document_name": "Page",
	"data": {
		"ItemId": "30447042-e0a3-4f15-8fd0-b3742d9538a9", 
		"title": "django pds test page", 
		"tags": ["mongoengine", "django-pds"]
	}
}' \
  http://localhost:8000/rest_api/insertor using postman:Continue reading thedjango-pds wikito know about CRUD operation made easy with Django PDS.