Skip to content

nanarino/nanarinorest

Repository files navigation

☘ 簡易接口模板

自用的 簡易的 restful api demo 模板。

接口頻率限制依賴 redis,自用不需要時可以卸掉這個功能

python fastapi sqlalchemy pgsql redis


初始運轉

記得先進入虛擬環境

# 安裝依賴
pip install -r requirements.txt
## 或者使用uv(試試套件咸更最新 若出問題了直接issue好吗🥰)
uv lock --upgrade

# 配置好./config.ini后創建空白資料表
python ./scripts/db_create.py

# 運轉項目
python app.py

API demo

增刪改查完備,啓動后見 swagger 文档

  • GET /demo/{id} 指定獲取單條
  • PUT /demo/{id} 修改指定單條
  • POST /demo 新增單條
  • GET /demos 分頁獲取多條
  • DELETE /demos 刪除指定多條

目錄結構

/nanarino/nanarinorest # cwd
│
├── app.py             # 程式入口
├── config.ini         # 配置文件
├── api
│   ├── __init__.py
│   ├── auth.py        # Oauth2授權 登錄注冊的api
│   ├── schemas.py     # 類型檢查以及DTO
│   └── demo.py        # 一組增刪改查的 DEMO api
├── db
│   ├── __init__.py
│   ├── base.py        # 資料物件基類
│   └── models.py      # 資料庫模型
├── util               # 工具函式
└── requirements.txt   # 依賴的pip包 
                       # 後面使用 `uv add -r requirements.txt` 補上了uv配置static/index.html      # 爲 DEMO api 編撰的 增删改查DEMO界面

示例界面

運行後訪問: http://127.0.0.1:8080/

UI 組件:UI5 Web Components UI5 Web Components

組件依賴使用 JSPM 工具 从 cdn 獲取 importmap,所以無需 nodejs 環境