Django-rest-swagger: how to group endpoints?

I am using the Django REST Framework and the django-rest-swagger library to create API endpoints. I would like to group some API URLs using a custom attribute instead of a URL.

For example, I have API endpoints and you want to group them by function:

# task list management GET /api/tasks/known - get known tasks list with their parameters GET /api/tasks - get last tasks list with their statuses # Tasks by ID management GET /api/task/12345 - get task result/status DELETE /api/task/12345 - Revoke task # Task by name management: # MyTask123 GET /api/tasks/MyTask123 - get task info (parameters, etc) POST /api/tasks/MyTask123 - async start new task # MySuperShinyTask777 GET /api/tasks/MySuperShinyTask777 - get task info (parameters, etc) POST /api/tasks/MySuperShinyTask777 - async start new task # scheduled tasks management GET /api/tasks/scheduled - get list of scheduled tasks # manage exact scheduled tasks POST /api/tasks/scheduled/MyTask123 - schedule new task GET /api/tasks/scheduled/12345 - get scheduled task details PUT /api/tasks/scheduled/12345 - change scheduled task DELETE /api/tasks/scheduled/12345 - delete scheduled task 

Therefore, I would like to show them grouped by role. Now they have grouped everything only with '/ api /' and what it is.

In urls.py I include it like this:

 url(r'^api/', include('api.urls'), name='my-api-root'), 

How can I do custom grouping for django-rest-swagger?

+6
source share
1 answer

You can have urls.py in the tasks application (I assume there is one) and declare them in your / tasks urls.

One for each of your endpoints.

 url(r'^ tasks/(?P<task_id>\w+)$', YourTaskView, name='task'), 

And this is in your root api urls.py

 url(r'^api/', include('api.tasks.urls'), name='my-api-root'), 

BUT it looks like you could use DRF routers

0
source

All Articles