-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ cookiecutter [email protected]:makimo/django-template.git | |
### Templates | ||
|
||
Nobody cares whether HTML in the browser is indented nicely or not. So the | ||
focus shifts to make templates programmer-friendly, treating logical blocks | ||
focus shifts to make templates programmer-friendly, treating logical blocks | ||
and HTML elements as first-class citizens for legibility. | ||
|
||
``` | ||
|
@@ -31,3 +31,58 @@ and HTML elements as first-class citizens for legibility. | |
``` | ||
|
||
Note: You can omit indentation after global scope `{% block %}` elements. | ||
|
||
### URL Naming | ||
|
||
Here are some tips for creating readable URL resource structure. | ||
|
||
#### 1. Path Params vs. Query Strings | ||
|
||
Use path params to locate the resource and query strings to parametrize | ||
the query. | ||
|
||
```python | ||
def get(self, request, object_id): | ||
option = self.request.GET.get('option', 'default') | ||
``` | ||
|
||
#### 2. Plural vs. Singular | ||
|
||
Use plural form to indicate the fact that a resource is a list. Use | ||
singular if object returned is a singleton. | ||
|
||
``` | ||
/users | ||
/users/{id}/config | ||
``` | ||
|
||
#### 3. Nesting Resources | ||
|
||
A good rule of thumb regarding resource resting is to nest resources if | ||
a child candidate resources cannot exist outside of its parent. Otherwise | ||
we may end up with multiple paths refering to the same resource. | ||
|
||
``` | ||
/users/{user_id}/config | ||
/user-configs?user_id={user_id} | ||
/user-configs/{user_id} | ||
/configs?type=user-configs&cfg_id={cfg_id} | ||
``` | ||
|
||
This is very ugly. | ||
|
||
Of course, it _may_ be more convienient and readable to break this rule. | ||
In such case, ensure that nesting is done only on strong relations. | ||
|
||
``` | ||
/author/{author_id}/books | ||
/books/{book_id} | ||
``` | ||
|
||
#### 4. Additional Reading | ||
|
||
1. [REST API Tutorial - Resource Naming]( | ||
https://www.restapitutorial.com/lessons/restfulresourcenaming.html) | ||
|
||
2. [REST URL Parameter Naming Conventions]( | ||
https://stackoverflow.com/questions/26357211/rest-url-path-parameter-naming-conventions) |