I'm writing API in DRF and had need to add nested routes.
Since drf-extensions are specified in official documentation I tend to use this package and it seemed to be working, but the documentation generated by Django Rest Framework doesn't include nested Viewset(route).
The documentation is generated using include_docs_urls from rest_framework.documentation
I would really like to have my nested endpoint described in generated documentation.
Is it possible?
djangorestframework==3.9.0
drf-extensions==0.5.0
Python2.7
Related
i'm using DRF in order to serve a set of API of my application, my api abstraction layer uses the ListCreateAPIView and i have many applications linked to my app, every application, implements an API abstraction level.
Now, what i'm trying to do, is to use the default DRF auto generated doc and "try-it" features that comes as "Battery included" from the framework, and in addition, adding to the breadcrumb "API Root" the list of all api that are implemented in the application without using ANY additional package/library, to be clear:
Is this possible?
Thanks
I am using Django-rest-swagger Package for documenting my API but I want to show only some URLs to document I have several apps in my project - some answers are USE Exclude but latest version it is not working -
I am using djangorestframework==3.5.1 and Django-rest-swagger==2.1.0 and Django-rest-framework for API.
I even tried render-schema and get_swagger_view(title='API Documentation', patterns=urlpatterns1).
but it's not working.
help me to find a solution.
Set exclude_from_schema = True in your View/Viewset or add it to the decorator (if you use them). This will exclude the view from swagger docs.
django-rest-swagger has changed a lot, in earlier versions there were settings for exclutish urls by name or namespace. Currently you need to exclude the View from the schema drf is generating, it's documented here http://www.django-rest-framework.org/api-guide/views/#api_view.
I am writing a Django app that exposes an API via DRF. Normally, I would generate the schema from code and expose the API docs via swagger-ui and the django rest framework swagger plugin for Django. The plugin uses 2 renderes to do so like:
schema_view = get_schema_view(
title='app api title',
renderer_classes=[OpenAPIRenderer, SwaggerUIRenderer]
)
My use case is a bit different this time. What I am trying to do is to render an already existing swagger.yml (I dont want to generate this dynamically from code). I guessed one needs to inject the existing swagger.yml into the SwaggerUIRenderer, but I failed to do so...
Is there any way to do this via the rest swagger plugin?
If you already have a definition file you don't need to use django_rest_swagger plugin, you can simply use Swagger-UI as recommended in this iusse.
https://github.com/marcgibbons/django-rest-swagger/issues/567
I would like to know if it is possible to build a REST Api using only Django (without Django REST).
I have following code in my views.py my Django (no REST Django)
from django.http import HttpResponse, JsonResponse
def get_something(request, object = None):
dummyDict = {'Debug':object}
return JsonResponse(dummyDict)
ulrs.py
url(r'^(?P<object>\w{1,50})$', views.get-something, name = "get-something"),
Can this work as REST API?
I tried testing using curl and I get following answer from my django server:
HTTP/1.0 200 OK
Date:
Server:
X-Frame-Options:
Content-Type: application/json
{"Debug": daodoaw}
You may do that though you'll have to add a lot of things to make an API RESTfull.
Your example is already missing proper response code for PUT / POST / PATCH / DELETE and doesn't respond correctly to OPTIONS
Ofcourse you can do these things with Django, but the advantage of django rest is that it is specifically created to handle api creation and management, Thus using django rest will be much more effective. When you look at the documentation of django rest, you could see that viewsets like ModelViewSet, GenericViewSet which are capable of handling any type of requests(POST, PUT, PATCH, etc...) in a two or three line code. Meanwhile while you using django you have to specify each and every case. Its just a case where DRF is more preferred).
What I try to say is, DRF is more handy in the case of API Creation and has a very good documentation in their official website
If you have to know about any specific part, please comment below
Thanks
Using Django is not a crime! We are given the liberty to use either DRFor Django.
Here are some of the situations when you can think of using DRF:
Let's imagine, you have developed a web application with django. What would happen if your client or you want a mobile version (android/iOS version) of your application? As multi-platform development is becoming the norm, using DRF can become crucial to reuse the same backend for both a mobile app and a web app.
Another comprehensive reason to use DRF is its super easy serialization facility.
If you want to segregate your front-end from Django provided templates, you are free to use modern javascript frameworks such as Vue, React or Angular for better design and to be dynamic as much as possible with your REST APIs.
When you use DRF, you are given ready-made view classes (ApiView, GenericAPIView, Viewsets) that are only a few lines of coding and able to handle all sorts of requests such as (POST, PUT, PATCH, etc...).
NOTE: Definitely, you can use Django depending on the project you are handling. In the case of building a web application that doesn't need to be accessed from other platforms, I would not use DRF. It entirely depends on the requirements.
I've written a json-schema to validate the json that comes with the POST request to my API. No I need to deserialize this json.
When I started builing the nested serializers structure I noticed that the process is very similar. So my question is: can my already written json-schema help with deserilization process?
[UPDATE] The blog post I linked below is quite outdated. Instead, I've gone and implemented a modern example of using JSONSchema validation and DRF together which you can see on this answer here.
Before I stumbled across your question I found this article which demonstrates how (and potentially when) to use a JSONSchema with Django REST Framework.
Django Rest Framework integrates well with models to provide out of the box validation, and ModelSerializers allow futher fine-grained custom validation. However, if you’re not using a model as the resource of your endpoint then the code required for custom validation of complex data structure can get hairy.
If there is a heavily nested data structure then a serializer can be used that has a nested serializer, which also has a nested serializer, and so on – or a JSON schema and custom JSON parser can be employed.
Using a JSON schema generation tool also provides a quick win: generate the canonical “pattern” of valid JSON structure using data known to be of the correct structure. This post will go through doing this JSON schema validation using Django Rest Framework.