diff --git a/README.md b/README.md index 3f57a03..9bed915 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Expect often updates as we discuss & decide upon different things. * [An example create API](#an-example-create-api) * [An example update API](#an-example-update-api) * [Nested serializers](#nested-serializers) +- [Urls](#urls) - [Exception Handling](#exception-handling) * [Raising Exceptions in Services / Selectors](#raising-exceptions-in-services--selectors) * [Handle Exceptions in APIs](#handle-exceptions-in-apis) @@ -406,6 +407,42 @@ class Serializer(serializers.Serializer): The implementation of `inline_serializer` can be found in `utils.py` in this repo. +## Urls + +We usually organize our urls the same way we organize our APIs - 1 url per API, meaning 1 url per action. + +A general rule of thumb is to split urls from different domains in their own `domain_patterns` list & include from `urlpatterns`. + +Here's an example with the APIs from above: + +```python +from django.urls import path, include + +from project.education.apis import ( + CourseCreateApi, + CourseUpdateApi, + CourseListApi, + CourseDetailApi, + CourseSpecificActionApi, +) + + +course_patterns = [ + path('', CourseListApi.as_view(), name='list'), + path('/', CourseDetailApi.as_view(), name='detail'), + path('create/', CourseCreateApi.as_view(), name='create'), + path('/update/', CourseUpdateApi.as_view(), name='update'), + path( + '/specific-action/', + CourseSpecificActionApi.as_view(), + name='specific-action' + ), +] + +urlpatterns = [ + path('courses/', include((course_patterns, 'courses'))), +] +``` ## Exception Handling