13

In djangorestframework, there is a browsable api. But how do I show a user an entire bird's eye view of all the possible API calls that he/she can make? I can only see one at a time right now and the user would have to already know the correct URL beforehand

i.e.,

http://localhost:8000/users
http://localhost:8000/books
http://localhost:8000/book/1/author

Thank you!

user798719
  • 9,619
  • 25
  • 84
  • 123
  • 5
    `./manage.py show_urls` should do the trick. https://stackoverflow.com/questions/1275486/django-how-can-i-see-a-list-of-urlpatterns – guitard00d123 Jan 30 '18 at 03:54
  • thank you but I mean I would like a user to be able to browse my api like the rest-swagger. It should show a table of contents of my entire API. Because I want to point a front-end developer and say "here is my entire api". You can do this using strongloop node.js api. – user798719 Jan 30 '18 at 05:35
  • why are you not using rest-swagger or drfdocs? – Muhammad Hassan Jan 30 '18 at 05:54
  • 2
    I thought the browsable API feature that ships with rest framework implies that actually browsing the API is possible out of the box. As I see it there is nothing to browse? By browse I mean at least seeing a table of contents that provides an overview of what is contained in my API – user798719 Jan 30 '18 at 06:58
  • 1
    May be you want something like [swagger](https://django-rest-swagger.readthedocs.io/en/latest/), swagger gives you a browsable interface when users and view all your endpoints and http verbs available for each call, it also documents itself using doc strings from your code. – Fer Mena Jan 30 '18 at 14:38
  • I know this is quite an old question but I'd like to make everyone aware that django-rest-framework have the following page on their site: https://www.django-rest-framework.org/topics/documenting-your-api/ It makes a reference to Swagger and drfdocs plus you need to know how to generate a schema using a SchemaView: https://www.django-rest-framework.org/api-guide/schemas/ – James Bellaby May 17 '20 at 18:35
  • Does this answer your question? [Django : How can I see a list of urlpatterns?](https://stackoverflow.com/questions/1275486/django-how-can-i-see-a-list-of-urlpatterns) – Vega May 22 '22 at 08:50

3 Answers3

6

The answer is as Klahnen said. Use this:

https://django-rest-swagger.readthedocs.io/en/latest/

It works out of the box for me and it is exactly what I was hoping for. I still maintain, though, that the term browsable API implies that there is a table of contents available for consumers of your API to see. This app is a lifesaver and perhaps it should be included!

user798719
  • 9,619
  • 25
  • 84
  • 123
3

Django-Rest-Swagger as mentioned in the accepted answer is no longer maintained.

This is a good alternative

https://github.com/axnsan12/drf-yasg

SohailAQ
  • 1,002
  • 1
  • 13
  • 25
0

Django-Rest-Swagger doesn't support OpenAPI 3.0 and is unlikely to support it soon, so if you want an actively maintained library that supports OpenAPI 3.0 then you should use drf-spectacular. It mostly works out of the box, and you can customize it a lot.

A side note: Your api client needs access to the internet so that it gets the swagger UI or ReDoc from CDNs. Alternatively you can serve those static files from your service with an optional additional package, the drf-spectacular-sidecar

dimyG
  • 687
  • 9
  • 19