Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mahenzon committed Dec 15, 2023
1 parent af3180a commit ef55753
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 35 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def add_routes(app: FastAPI):
router: APIRouter = APIRouter()
RoutersJSONAPI(
router=router,
path="/user",
path="/users",
tags=["User"],
class_detail=UserDetailView,
class_list=UserListView,
Expand Down Expand Up @@ -195,11 +195,11 @@ if __name__ == "__main__":

This example provides the following API structure:

| URL | method | endpoint | Usage |
|------------------|--------|-------------|---------------------------|
| `/user` | GET | user_list | Get a collection of users |
| `/user` | POST | user_list | Create a user |
| `/user` | DELETE | user_list | Delete users |
| `/user/{obj_id}` | GET | user_detail | Get user details |
| `/user/{obj_id}` | PATCH | user_detail | Update a user |
| `/user/{obj_id}` | DELETE | user_detail | Delete a user |
| URL | method | endpoint | Usage |
|-------------------|--------|-------------|---------------------------|
| `/users` | GET | user_list | Get a collection of users |
| `/users` | POST | user_list | Create a user |
| `/users` | DELETE | user_list | Delete users |
| `/users/{obj_id}` | GET | user_detail | Get user details |
| `/users/{obj_id}` | PATCH | user_detail | Update a user |
| `/users/{obj_id}` | DELETE | user_detail | Delete a user |
15 changes: 13 additions & 2 deletions docs/api_limited_methods_example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Set ``methods`` on Routers registration:
RoutersJSONAPI(
router=router,
path="/user",
path="/users",
tags=["User"],
class_detail=UserDetailView,
class_list=UserListView,
Expand All @@ -29,7 +29,18 @@ Set ``methods`` on Routers registration:
)
Full code example:
This will limit generated views to:

======================== ====== ============= ===========================
URL method endpoint Usage
======================== ====== ============= ===========================
/users GET user_list Get a collection of users
/users POST user_list Create a user
/users/{user_id} GET user_detail Get user details
======================== ====== ============= ===========================


Full code example (should run "as is"):

.. literalinclude:: ../examples/api_limited_methods.py
:language: python
24 changes: 12 additions & 12 deletions docs/filtering.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ So this is a first example:

.. sourcecode:: http

GET /user?filter=[{"name":"first_name","op":"eq","val":"John"}] HTTP/1.1
GET /users?filter=[{"name":"first_name","op":"eq","val":"John"}] HTTP/1.1
Accept: application/vnd.api+json

In this example we want to retrieve user records for people named John. So we can see that the filtering interface completely fits that of SQLAlchemy: a list a filter information.
Expand All @@ -37,7 +37,7 @@ Example with field:

.. sourcecode:: http

GET /user?filter=[{"name":"first_name","op":"eq","field":"birth_date"}] HTTP/1.1
GET /users?filter=[{"name":"first_name","op":"eq","field":"birth_date"}] HTTP/1.1
Accept: application/vnd.api+json

In this example, we want to retrieve people whose name is equal to their birth_date. This example is absurd, it's just here to explain the syntax of this kind of filter.
Expand Down Expand Up @@ -74,7 +74,7 @@ There is a shortcut to achieve the same filtering:

.. sourcecode:: http

GET /user?filter=[{"name":"group.name","op":"ilike","val":"%admin%"}] HTTP/1.1
GET /users?filter=[{"name":"group.name","op":"ilike","val":"%admin%"}] HTTP/1.1
Accept: application/vnd.api+json

You can also use boolean combination of operations:
Expand Down Expand Up @@ -116,22 +116,22 @@ You can also use boolean combination of operations:

.. sourcecode:: http

GET /user?filter=[{"name":"group.name","op":"ilike","val":"%admin%"},{"or":[{"not":{"name":"first_name","op":"eq","val":"John"}},{"and":[{"name":"first_name","op":"like","val":"%Jim%"},{"name":"date_create","op":"gt","val":"1990-01-01"}]}]}] HTTP/1.1
GET /users?filter=[{"name":"group.name","op":"ilike","val":"%admin%"},{"or":[{"not":{"name":"first_name","op":"eq","val":"John"}},{"and":[{"name":"first_name","op":"like","val":"%Jim%"},{"name":"date_create","op":"gt","val":"1990-01-01"}]}]}] HTTP/1.1
Accept: application/vnd.api+json


Filtering records by a field that is null

.. sourcecode:: http

GET /user?filter=[{"name":"name","op":"is_","val":null}] HTTP/1.1
GET /users?filter=[{"name":"name","op":"is_","val":null}] HTTP/1.1
Accept: application/vnd.api+json

Filtering records by a field that is not null

.. sourcecode:: http

GET /user?filter=[{"name":"name","op":"isnot","val":null}] HTTP/1.1
GET /users?filter=[{"name":"name","op":"isnot","val":null}] HTTP/1.1
Accept: application/vnd.api+json


Expand Down Expand Up @@ -172,22 +172,22 @@ For example

.. sourcecode:: http

GET /user?filter[first_name]=John HTTP/1.1
GET /users?filter[first_name]=John HTTP/1.1
Accept: application/vnd.api+json

equals:

.. sourcecode:: http

GET /user?filter=[{"name":"first_name","op":"eq","val":"John"}] HTTP/1.1
GET /users?filter=[{"name":"first_name","op":"eq","val":"John"}] HTTP/1.1
Accept: application/vnd.api+json


You can also use more than one simple filter in a request:

.. sourcecode:: http

GET /user?filter[first_name]=John&filter[gender]=male HTTP/1.1
GET /users?filter[first_name]=John&filter[gender]=male HTTP/1.1
Accept: application/vnd.api+json

which is equal to:
Expand All @@ -209,17 +209,17 @@ which is equal to:

.. sourcecode:: http

GET /user?filter=[{"name":"first_name","op":"eq","val":"John"},{"name":"gender","op":"eq","val":"male"}] HTTP/1.1
GET /users?filter=[{"name":"first_name","op":"eq","val":"John"},{"name":"gender","op":"eq","val":"male"}] HTTP/1.1

You can also use relationship attribute in a request:

.. sourcecode:: http

GET /user?filter[group_id]=1 HTTP/1.1
GET /users?filter[group_id]=1 HTTP/1.1
Accept: application/vnd.api+json

which is equal to:

.. sourcecode:: http

GET /user?filter=[{"name":"group.id","op":"eq","val":"1"}] HTTP/1.1
GET /users?filter=[{"name":"group.id","op":"eq","val":"1"}] HTTP/1.1
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def add_routes(app: FastAPI):
router: APIRouter = APIRouter()
RoutersJSONAPI(
router=router,
path="/user",
path="/users",
tags=["User"],
class_detail=UserDetailView,
class_list=UserListView,
Expand Down
16 changes: 8 additions & 8 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@ This example provides the following API:
+----------------+--------+----------------+---------------------------------+
| url | method | endpoint | action |
+================+========+================+=================================+
| /user | GET | user_list | Retrieve a collection of users |
| /users | GET | user_list | Retrieve a collection of users |
+----------------+--------+----------------+---------------------------------+
| /user | POST | user_list | Create a user |
| /users | POST | user_list | Create a user |
+----------------+--------+----------------+---------------------------------+
| /user/<int:id> | GET | user_detail | Retrieve details of a user |
| /users/<int:id> | GET | user_detail | Retrieve details of a user |
+----------------+--------+----------------+---------------------------------+
| /user/<int:id> | PATCH | user_detail | Update a user |
| /users/<int:id> | PATCH | user_detail | Update a user |
+----------------+--------+----------------+---------------------------------+
| /user/<int:id> | DELETE | user_detail | Delete a user |
| /users/<int:id> | DELETE | user_detail | Delete a user |
+----------------+--------+----------------+---------------------------------+

in developing

+-------------------------------------------+--------+------------------+------------------------------------------------------+
| url | method | endpoint | action |
+===========================================+========+==================+======================================================+
| /user/<int:id>/group | GET | computer_list | Retrieve a collection computers related to a user |
| /users/<int:id>/group | GET | computer_list | Retrieve a collection computers related to a user |
+-------------------------------------------+--------+------------------+------------------------------------------------------+
| /user/<int:id>/group | POST | computer_list | Create a computer related to a user |
| /users/<int:id>/group | POST | computer_list | Create a computer related to a user |
+-------------------------------------------+--------+------------------+------------------------------------------------------+
| /user/<int:id>/relationships/group | GET | user_computers | Retrieve relationships between a user and computers |
| /users/<int:id>/relationships/group | GET | user_computers | Retrieve relationships between a user and computers |
+-------------------------------------------+--------+------------------+------------------------------------------------------+
| /users/<int:id>/relationships/computers | POST | user_computers | Create relationships between a user and computers |
+-------------------------------------------+--------+------------------+------------------------------------------------------+
Expand Down
2 changes: 1 addition & 1 deletion examples/api_for_tortoise_orm/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def add_routes(app: FastAPI) -> List[Dict[str, Any]]:
# TODO: fix example
RoutersJSONAPI(
router=routers,
path="/user",
path="/users",
tags=["User"],
class_detail=UserDetail,
class_list=UserList,
Expand Down
2 changes: 1 addition & 1 deletion examples/api_limited_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def add_routes(app: FastAPI):
router: APIRouter = APIRouter()
RoutersJSONAPI(
router=router,
path="/user",
path="/users",
tags=["User"],
class_detail=UserDetailView,
class_list=UserListView,
Expand Down
2 changes: 1 addition & 1 deletion examples/api_minimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def add_routes(app: FastAPI):
router: APIRouter = APIRouter()
RoutersJSONAPI(
router=router,
path="/user",
path="/users",
tags=["User"],
class_detail=UserDetailView,
class_list=UserListView,
Expand Down

0 comments on commit ef55753

Please sign in to comment.