Skip to content

Commit f72dd9d

Browse files
authored
Merge pull request #48 from igorbenav/igorbenav-patch-1
Update README.md
2 parents 613c9ef + d53f833 commit f72dd9d

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ poetry install
265265
Ensuring it ran without any problem.
266266

267267
#### 4.2.2. Running PostgreSQL With Docker
268+
> [!NOTE]
268269
> If you already have a PostgreSQL running, you may skip this step.
269270
270271
Install docker if you don't have it yet, then run:
@@ -293,6 +294,7 @@ docker run -d \
293294
```
294295

295296
#### 4.2.3. Running redis With Docker
297+
> [!NOTE]
296298
> If you already have a redis running, you may skip this step.
297299
298300
Install docker if you don't have it yet, then run:
@@ -321,12 +323,13 @@ While in the `src` folder, run to start the application with uvicorn server:
321323
```sh
322324
poetry run uvicorn app.main:app --reload
323325
```
326+
> [!TIP]
324327
> The --reload flag enables auto-reload once you change (and save) something in the project
325328
326329
### 4.3 Creating the first superuser
327330
#### 4.3.1 Docker Compose
328331

329-
> **Warning**
332+
> [!WARNING]
330333
> Make sure DB and tables are created before running create_superuser (db should be running and the api should run at least once before)
331334
332335
If you are using docker compose, you should uncomment this part of the docker-compose.yml:
@@ -384,7 +387,7 @@ poetry run python -m scripts.create_first_superuser
384387

385388
### 4.3.3 Creating the first tier
386389

387-
> **Warning**
390+
> [!WARNING]
388391
> Make sure DB and tables are created before running create_tier (db should be running and the api should run at least once before)
389392
390393
To create the first tier it's similar, you just replace `create_superuser` for `create_tier` service or `create_first_superuser` to `create_first_tier` for scripts. If using `docker compose`, do not forget to uncomment the `create_tier` service in `docker-compose.yml`.
@@ -400,6 +403,7 @@ And to apply the migration
400403
poetry run alembic upgrade head
401404
```
402405

406+
[!NOTE]
403407
> If you do not have poetry, you may run it without poetry after running `pip install alembic`
404408
405409
## 5. Extending
@@ -505,7 +509,7 @@ Create the new entities and relationships and add them to the model
505509
### 5.3 SQLAlchemy Models
506510
Inside `app/models`, create a new `entity.py` for each new entity (replacing entity with the name) and define the attributes according to [SQLAlchemy 2.0 standards](https://docs.sqlalchemy.org/en/20/orm/mapping_styles.html#orm-mapping-styles):
507511

508-
> **Warning**
512+
> [!WARNING]
509513
> Note that since it inherits from `Base`, the new model is mapped as a python `dataclass`, so optional attributes (arguments with a default value) should be defined after required attributes.
510514
511515
```python
@@ -612,7 +616,7 @@ user = await crud_users.get_multi(
612616
name="User Userson"
613617
)
614618
```
615-
> **Warning**
619+
> [!WARNING]
616620
> Note that get_multi returns a python `dict`.
617621
618622
Which will return a python dict with the following structure:
@@ -812,7 +816,7 @@ The `cache` decorator allows you to cache the results of FastAPI endpoint functi
812816

813817
Caching the response of an endpoint is really simple, just apply the `cache` decorator to the endpoint function.
814818

815-
> **Warning**
819+
> [!WARNING]
816820
> Note that you should always pass request as a variable to your endpoint function if you plan to use the cache decorator.
817821
818822
```python
@@ -912,7 +916,7 @@ async def patch_post(
912916
...
913917
```
914918

915-
> **Warning**
919+
> [!WARNING]
916920
> Note that adding `to_invalidate_extra` will not work for **GET** requests.
917921
918922
#### Invalidate Extra By Pattern
@@ -974,7 +978,7 @@ async def patch_post(
974978

975979
Now it will invalidate all caches with a key that matches the pattern `"{username}_posts:*`, which will work for the paginated responses.
976980

977-
> **Warning**
981+
> [!CAUTION]
978982
> Using `pattern_to_invalidate_extra` can be resource-intensive on large datasets. Use it judiciously and consider the potential impact on Redis performance. Be cautious with patterns that could match a large number of keys, as deleting many keys simultaneously may impact the performance of the Redis server.
979983
980984
#### Client-side Caching
@@ -1058,7 +1062,7 @@ And a `pro` tier:
10581062

10591063
Then I'll associate a `rate_limit` for the path `api/v1/tasks/task` for each of them, I'll associate a `rate limit` for the path `api/v1/tasks/task`.
10601064

1061-
> **Warning**
1065+
> [!WARNING]
10621066
> Do not forget to add `api/v1/...` or any other prefix to the beggining of your path. For the structure of the boilerplate, `api/v1/<rest_of_the_path>`
10631067
10641068
1 request every hour (3600 seconds) for the free tier:
@@ -1124,13 +1128,13 @@ curl -X POST 'http://127.0.0.1:8000/api/v1/tasks/task?message=test' \
11241128
-H 'Authorization: Bearer <your-token-here>'
11251129
```
11261130

1127-
> **Warning**
1131+
> [!TIP]
11281132
> Since the `rate_limiter` dependency uses the `get_optional_user` dependency instead of `get_current_user`, it will not require authentication to be used, but will behave accordingly if the user is authenticated (and token is passed in header). If you want to ensure authentication, also use `get_current_user` if you need.
11291133
11301134
To change a user's tier, you may just use the `PATCH api/v1/user/{username}/tier` endpoint.
11311135
Note that for flexibility (since this is a boilerplate), it's not necessary to previously inform a tier_id to create a user, but you probably should set every user to a certain tier (let's say `free`) once they are created.
11321136

1133-
> **Warning**
1137+
> [!WARNING]
11341138
> If a user does not have a `tier` or the tier does not have a defined `rate limit` for the path and the token is still passed to the request, the default `limit` and `period` will be used, this will be saved in `app/logs`.
11351139
11361140
### 5.12 Running
@@ -1172,7 +1176,7 @@ Should be changed to:
11721176
command: gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000
11731177
```
11741178

1175-
> **Warning**
1179+
> [!CAUTION]
11761180
> Do not forget to set the `ENVIRONMENT` in `.env` to `production` unless you want the API docs to be public.
11771181
11781182
More on running it in production later.

0 commit comments

Comments
 (0)