Skip to content

Commit 43ff498

Browse files
author
ks6088ts
committed
setup FastAPI server
1 parent 032af67 commit 43ff498

File tree

5 files changed

+555
-3
lines changed

5 files changed

+555
-3
lines changed

Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jupyterlab: ## run Jupyter Lab
5858
# ---
5959
DOCKER_REPO_NAME ?= ks6088ts
6060
DOCKER_IMAGE_NAME ?= template-fastapi
61-
DOCKER_COMMAND ?=
61+
DOCKER_COMMAND ?= fastapi run main.py --help
6262

6363
# Tools
6464
TOOLS_DIR ?= /usr/local/bin
@@ -103,3 +103,20 @@ docs-serve: ## serve documentation
103103

104104
.PHONY: ci-test-docs
105105
ci-test-docs: docs ## run CI test for documentation
106+
107+
# ---
108+
# Project
109+
# ---
110+
111+
.PHONY: run
112+
run: ## run FastAPI server
113+
uv run fastapi run main.py \
114+
--host 0.0.0.0 \
115+
--port 8000
116+
117+
.PHONY: dev
118+
dev: ## run FastAPI server in development mode
119+
uv run fastapi dev main.py \
120+
--host 0.0.0.0 \
121+
--port 8000 \
122+
--reload

docs/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
# template-fastapi
2+
3+
## FastAPI
4+
5+
- [FastAPI](https://fastapi.tiangolo.com/)

main.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from fastapi import FastAPI
2+
3+
app = FastAPI()
4+
5+
6+
@app.get("/")
7+
def read_root():
8+
return {"Hello": "World"}
9+
10+
11+
@app.get("/items/{item_id}")
12+
def read_item(item_id: int, q: str | None = None):
13+
return {"item_id": item_id, "q": q}

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ version = "0.0.1"
44
description = "A GitHub template repository for Python"
55
readme = "README.md"
66
requires-python = ">=3.10"
7-
dependencies = []
7+
dependencies = [
8+
"fastapi[standard]>=0.115.12",
9+
]
810

911
[project.optional-dependencies]
1012
docs = [

0 commit comments

Comments
 (0)