Skip to content

Commit

Permalink
update (frameworks/fastapi): two versions and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
santanche committed Aug 11, 2024
1 parent 8a2fcfe commit febeb11
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
17 changes: 17 additions & 0 deletions frameworks/fastapi/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# FastAPI
https://fastapi.tiangolo.com/

# Installing

This statement forces a specific version of FastAPI installation when the default is not the latest.

~~~
pip3 install "fastapi[standard]"==0.112.0
~~~

# Simple Example

* Version for Python 3.7+ using `Union[ ]` for optional fields:
~~~
fastapi dev main_3_07.py
~~~

* Version for Python 3.10+ using `type | None` for optional fields:
~~~
fastapi dev main_3_10.py
~~~
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

app = FastAPI()


@app.get("/")
def read_root():
return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}
return {"item_id": item_id, "q": q}
11 changes: 11 additions & 0 deletions frameworks/fastapi/basic/main_3_10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
return {"Hello": "World"}

@app.get("/items/{item_id}")
def read_item(item_id: int, q: str | None = None):
return {"item_id": item_id, "q": q}

0 comments on commit febeb11

Please sign in to comment.