Skip to content

Commit 6a85b4b

Browse files
authored
Add FastAPI example app (#106)
1 parent cf8f141 commit 6a85b4b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

examples/fastapi_app.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from __future__ import annotations
2+
import typing
3+
4+
from microbootstrap.bootstrappers.fastapi import FastApiBootstrapper
5+
from microbootstrap.granian_server import create_granian_server
6+
from microbootstrap.settings import FastApiSettings
7+
8+
9+
if typing.TYPE_CHECKING:
10+
import fastapi
11+
12+
13+
class Settings(FastApiSettings): ...
14+
15+
16+
settings = Settings()
17+
18+
19+
def create_app() -> fastapi.FastAPI:
20+
app = FastApiBootstrapper(settings).bootstrap()
21+
22+
@app.get("/")
23+
async def hello_world() -> dict[str, str]:
24+
return {"hello": "world"}
25+
26+
return app
27+
28+
29+
if __name__ == "__main__":
30+
create_granian_server("examples.fastapi_app:create_app", settings, factory=True).serve()

0 commit comments

Comments
 (0)