Introduce basic urls section

This commit is contained in:
Radoslav Georgiev 2019-10-27 16:57:34 +02:00
parent 00b8d772ec
commit 94c04c1cee

View File

@ -23,6 +23,7 @@ Expect often updates as we discuss & decide upon different things.
* [An example create API](#an-example-create-api) * [An example create API](#an-example-create-api)
* [An example update API](#an-example-update-api) * [An example update API](#an-example-update-api)
* [Nested serializers](#nested-serializers) * [Nested serializers](#nested-serializers)
- [Urls](#urls)
- [Exception Handling](#exception-handling) - [Exception Handling](#exception-handling)
* [Raising Exceptions in Services / Selectors](#raising-exceptions-in-services--selectors) * [Raising Exceptions in Services / Selectors](#raising-exceptions-in-services--selectors)
* [Handle Exceptions in APIs](#handle-exceptions-in-apis) * [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. 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('<int:course_id>/', CourseDetailApi.as_view(), name='detail'),
path('create/', CourseCreateApi.as_view(), name='create'),
path('<int:course_id>/update/', CourseUpdateApi.as_view(), name='update'),
path(
'<int:course_id>/specific-action/',
CourseSpecificActionApi.as_view(),
name='specific-action'
),
]
urlpatterns = [
path('courses/', include((course_patterns, 'courses'))),
]
```
## Exception Handling ## Exception Handling