Skip to content

Commit

Permalink
docs: upgrade README for show the new feature
Browse files Browse the repository at this point in the history
The "new feature" refers to the possibility of adding the controllers
one by one to the FastAPI instances and the need to inherit from an
APIController base class.
  • Loading branch information
leynier committed May 10, 2022
1 parent de489bd commit 0315bb9
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ pip install fastapi-control

```python
from fastapi import FastAPI

from fastapi_control import add_controllers, controller, get, inject
from fastapi_control import (
APIController,
add_controller,
add_controllers,
controller,
get,
inject,
)


# Optionally declares an abstraction
Expand Down Expand Up @@ -61,10 +67,11 @@ class NestedGretterImplementation:
return self.gretter.greet()


# With the @controller decorator, we can declare class-based routing (also
# called controller) and it has the same parameters as FastAPI's APIRouter
# With the @controller decorator and inheriting from APIController, we can
# declare class-based routing (also called controller) and it has the same
# parameters as FastAPI's APIRouter
@controller(prefix="/home")
class HomeController:
class HomeController(APIController):
# When the @controller decorator is used, the arguments of the __init__
# method are automatically injected (if the @inject decorator was used
# in the argument type declarations)
Expand Down Expand Up @@ -97,6 +104,12 @@ class HomeController:
api = FastAPI()
# Finally, it is necessary to add the controllers to the FastAPI instance
add_controllers(api)

# If you want to have multiple FastAPI instances with different controllers,
# you can use the add_controller method to add the desired controllers to
# the desired FastAPI instance one by one.
other_api = FastAPI()
add_controller(other_api, HomeController)
```

## Inspirations
Expand Down

0 comments on commit 0315bb9

Please sign in to comment.