sanic-api 0.2.9__tar.gz → 0.3.0a1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sanic_api-0.3.0a1/.gitignore +145 -0
- sanic_api-0.3.0a1/.pre-commit-config.yaml +18 -0
- sanic_api-0.3.0a1/CHANGELOG.md +97 -0
- sanic_api-0.3.0a1/COMMIT_GUIDE.MD +10 -0
- {sanic-api-0.2.9 → sanic_api-0.3.0a1}/LICENSE.txt +0 -0
- {sanic-api-0.2.9 → sanic_api-0.3.0a1}/PKG-INFO +32 -5
- sanic-api-0.2.9/README.MD → sanic_api-0.3.0a1/README.md +79 -79
- {sanic-api-0.2.9 → sanic_api-0.3.0a1}/example/__init__.py +0 -0
- sanic_api-0.3.0a1/example/app.py +56 -0
- sanic_api-0.3.0a1/example/log.txt +1584 -0
- sanic_api-0.3.0a1/example/mini_app.py +11 -0
- sanic_api-0.3.0a1/images/logo.png +0 -0
- sanic_api-0.3.0a1/pyproject.toml +161 -0
- sanic_api-0.3.0a1/requirements-dev.lock +98 -0
- sanic_api-0.3.0a1/requirements.lock +82 -0
- sanic_api-0.3.0a1/src/sanic_api/__init__.py +3 -0
- sanic_api-0.3.0a1/src/sanic_api/api/__init__.py +17 -0
- sanic_api-0.3.0a1/src/sanic_api/api/model.py +0 -0
- sanic_api-0.3.0a1/src/sanic_api/api/request.py +138 -0
- sanic_api-0.3.0a1/src/sanic_api/api/response.py +34 -0
- sanic_api-0.3.0a1/src/sanic_api/app.py +275 -0
- sanic_api-0.3.0a1/src/sanic_api/config/__init__.py +1 -0
- sanic_api-0.3.0a1/src/sanic_api/config/setting.py +71 -0
- sanic_api-0.3.0a1/src/sanic_api/logger/__init__.py +0 -0
- sanic_api-0.3.0a1/src/sanic_api/logger/config.py +99 -0
- sanic_api-0.3.0a1/src/sanic_api/logger/extension.py +129 -0
- sanic_api-0.3.0a1/src/sanic_api/openapi/__init__.py +0 -0
- sanic_api-0.3.0a1/src/sanic_api/openapi/extension.py +41 -0
- sanic_api-0.3.0a1/src/sanic_api/utils/__init__.py +0 -0
- {sanic-api-0.2.9/sanic_api → sanic_api-0.3.0a1/src/sanic_api/utils}/enum.py +58 -88
- sanic-api-0.2.9/example/__main__.py +0 -19
- sanic-api-0.2.9/example/api/__init__.py +0 -1
- sanic-api-0.2.9/example/api/t1/__init__.py +0 -2
- sanic-api-0.2.9/example/api/t1/t1_1.py +0 -22
- sanic-api-0.2.9/example/api/t1/t1_2.py +0 -9
- sanic-api-0.2.9/example/api/t2/__init__.py +0 -1
- sanic-api-0.2.9/example/api/t2/t2.py +0 -9
- sanic-api-0.2.9/example/api/t2/t3/__init__.py +0 -1
- sanic-api-0.2.9/example/api/t2/t3/t3.py +0 -9
- sanic-api-0.2.9/example/api/user.py +0 -89
- sanic-api-0.2.9/example/api/validator.py +0 -97
- sanic-api-0.2.9/example/app.py +0 -62
- sanic-api-0.2.9/example/settings.py +0 -10
- sanic-api-0.2.9/pyproject.toml +0 -94
- sanic-api-0.2.9/sanic_api/__init__.py +0 -21
- sanic-api-0.2.9/sanic_api/api/__init__.py +0 -2
- sanic-api-0.2.9/sanic_api/api/api.py +0 -177
- sanic-api-0.2.9/sanic_api/api/exception.py +0 -46
- sanic-api-0.2.9/sanic_api/api/extend.py +0 -25
- sanic-api-0.2.9/sanic_api/api/handle_exception.py +0 -61
- sanic-api-0.2.9/sanic_api/api/model.py +0 -46
- sanic-api-0.2.9/sanic_api/api/validators.py +0 -76
- sanic-api-0.2.9/sanic_api/config/__init__.py +0 -1
- sanic-api-0.2.9/sanic_api/config/sanic.py +0 -19
- sanic-api-0.2.9/sanic_api/config/sanic_api.py +0 -11
- sanic-api-0.2.9/sanic_api/config/setting.py +0 -30
- sanic-api-0.2.9/sanic_api/logger/__init__.py +0 -1
- sanic-api-0.2.9/sanic_api/logger/config.py +0 -77
- sanic-api-0.2.9/sanic_api/logger/extend.py +0 -71
- sanic-api-0.2.9/sanic_api/logger/sanic_http.py +0 -68
- sanic-api-0.2.9/sanic_api/openapi/__init__.py +0 -7
- sanic-api-0.2.9/sanic_api/openapi/openapi.py +0 -102
- sanic-api-0.2.9/sanic_api/utils.py +0 -112
@@ -0,0 +1,145 @@
|
|
1
|
+
# ---> Python
|
2
|
+
# Byte-compiled / optimized / DLL files
|
3
|
+
__pycache__/
|
4
|
+
*.py[cod]
|
5
|
+
*$py.class
|
6
|
+
|
7
|
+
# C extensions
|
8
|
+
*.so
|
9
|
+
|
10
|
+
# pycharm
|
11
|
+
.idea/
|
12
|
+
|
13
|
+
# rye
|
14
|
+
.python-version
|
15
|
+
|
16
|
+
# Distribution / packaging
|
17
|
+
.Python
|
18
|
+
build/
|
19
|
+
develop-eggs/
|
20
|
+
dist/
|
21
|
+
downloads/
|
22
|
+
eggs/
|
23
|
+
.eggs/
|
24
|
+
lib/
|
25
|
+
lib64/
|
26
|
+
parts/
|
27
|
+
sdist/
|
28
|
+
var/
|
29
|
+
wheels/
|
30
|
+
share/python-wheels/
|
31
|
+
*.egg-info/
|
32
|
+
.installed.cfg
|
33
|
+
*.egg
|
34
|
+
MANIFEST
|
35
|
+
|
36
|
+
# PyInstaller
|
37
|
+
# Usually these files are written by a python script from a template
|
38
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
39
|
+
*.manifest
|
40
|
+
*.spec
|
41
|
+
|
42
|
+
# Installer logs
|
43
|
+
pip-log.txt
|
44
|
+
pip-delete-this-directory.txt
|
45
|
+
|
46
|
+
# Unit test / coverage reports
|
47
|
+
htmlcov/
|
48
|
+
.tox/
|
49
|
+
.nox/
|
50
|
+
.coverage
|
51
|
+
.coverage.*
|
52
|
+
.cache
|
53
|
+
nosetests.xml
|
54
|
+
coverage.xml
|
55
|
+
*.cover
|
56
|
+
*.py,cover
|
57
|
+
.hypothesis/
|
58
|
+
.pytest_cache/
|
59
|
+
cover/
|
60
|
+
|
61
|
+
# Translations
|
62
|
+
*.mo
|
63
|
+
*.pot
|
64
|
+
|
65
|
+
# Django stuff:
|
66
|
+
*.log
|
67
|
+
local_settings.py
|
68
|
+
db.sqlite3
|
69
|
+
db.sqlite3-journal
|
70
|
+
|
71
|
+
# Flask stuff:
|
72
|
+
instance/
|
73
|
+
.webassets-cache
|
74
|
+
|
75
|
+
# Scrapy stuff:
|
76
|
+
.scrapy
|
77
|
+
|
78
|
+
# Sphinx documentation
|
79
|
+
docs/_build/
|
80
|
+
|
81
|
+
# PyBuilder
|
82
|
+
.pybuilder/
|
83
|
+
target/
|
84
|
+
|
85
|
+
# Jupyter Notebook
|
86
|
+
.ipynb_checkpoints
|
87
|
+
|
88
|
+
# IPython
|
89
|
+
profile_default/
|
90
|
+
ipython_config.py
|
91
|
+
|
92
|
+
# pyenv
|
93
|
+
# For a library or package, you might want to ignore these files since the code is
|
94
|
+
# intended to run in multiple environments; otherwise, check them in:
|
95
|
+
# .python-version
|
96
|
+
|
97
|
+
# pipenv
|
98
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
99
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
100
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
101
|
+
# install all needed dependencies.
|
102
|
+
#Pipfile.lock
|
103
|
+
|
104
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
105
|
+
__pypackages__/
|
106
|
+
|
107
|
+
# Celery stuff
|
108
|
+
celerybeat-schedule
|
109
|
+
celerybeat.pid
|
110
|
+
|
111
|
+
# SageMath parsed files
|
112
|
+
*.sage.py
|
113
|
+
|
114
|
+
# Environments
|
115
|
+
.env
|
116
|
+
.venv
|
117
|
+
env/
|
118
|
+
venv/
|
119
|
+
ENV/
|
120
|
+
env.bak/
|
121
|
+
venv.bak/
|
122
|
+
|
123
|
+
# Spyder project settings
|
124
|
+
.spyderproject
|
125
|
+
.spyproject
|
126
|
+
|
127
|
+
# Rope project settings
|
128
|
+
.ropeproject
|
129
|
+
|
130
|
+
# mkdocs documentation
|
131
|
+
/site
|
132
|
+
|
133
|
+
# mypy
|
134
|
+
.mypy_cache/
|
135
|
+
.dmypy.json
|
136
|
+
dmypy.json
|
137
|
+
|
138
|
+
# Pyre type checker
|
139
|
+
.pyre/
|
140
|
+
|
141
|
+
# pytype static type analyzer
|
142
|
+
.pytype/
|
143
|
+
|
144
|
+
# Cython debug symbols
|
145
|
+
cython_debug/
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# See https://pre-commit.com for more information
|
2
|
+
# See https://pre-commit.com/hooks.html for more hooks
|
3
|
+
repos:
|
4
|
+
# bandit
|
5
|
+
- repo: https://github.com/PyCQA/bandit
|
6
|
+
rev: 1.7.10
|
7
|
+
hooks:
|
8
|
+
- id: bandit
|
9
|
+
args: [ "-c", "pyproject.toml" ]
|
10
|
+
additional_dependencies: [ "bandit[toml]" ]
|
11
|
+
|
12
|
+
# ruff
|
13
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
14
|
+
rev: 'v0.6.9'
|
15
|
+
hooks:
|
16
|
+
- id: ruff
|
17
|
+
args: [ --fix, --exit-non-zero-on-fix, --show-fixes ]
|
18
|
+
- id: ruff-format
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [0.2.6] -2023-07-05
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
|
12
|
+
- 修复配置类报错的问题
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
|
16
|
+
- 升级sanic依赖版本为22.3
|
17
|
+
- 增加`setuptools`依赖
|
18
|
+
|
19
|
+
## [0.2.5] - 2023-04-09
|
20
|
+
|
21
|
+
### Added
|
22
|
+
|
23
|
+
- 支持捕获在中间件期间发生错误的异常情况
|
24
|
+
- 增加配置类功能
|
25
|
+
- 示例文件更新
|
26
|
+
- 工具方法中新增自动蓝图方法
|
27
|
+
|
28
|
+
### Changed
|
29
|
+
|
30
|
+
- 默认的json dumps方法改为orjson
|
31
|
+
- sanic 最低版本依赖更新至22.12
|
32
|
+
- 优化API响应封装及响应文档的生成
|
33
|
+
|
34
|
+
### Fixed
|
35
|
+
|
36
|
+
- 修复openapi tag重复的问题
|
37
|
+
- 修复日志级别判断不准问题
|
38
|
+
|
39
|
+
## [0.2.4] - 2023-02-05
|
40
|
+
|
41
|
+
### Fixed
|
42
|
+
|
43
|
+
- 修复示例文件不生效的问题
|
44
|
+
|
45
|
+
## [0.2.3] - 2023-02-03
|
46
|
+
|
47
|
+
### Fixed
|
48
|
+
|
49
|
+
- 修复无蓝图的api接口blueprint.ctx.desc报错的问题
|
50
|
+
- 实现_missing_方法,修复枚举基类无法识别枚举值的问题
|
51
|
+
|
52
|
+
### Changed
|
53
|
+
|
54
|
+
- 请求接口无参数时访问日志中不打印 “args:”
|
55
|
+
- 枚举基类字段类名称修改,避免重名
|
56
|
+
|
57
|
+
### Added
|
58
|
+
|
59
|
+
- API接口类支持自定义接口标签和接口描述
|
60
|
+
- 添加types-ujson包
|
61
|
+
- 自动生成的文档支持识别必须和可选参数
|
62
|
+
- 枚举基类增加to_desc方法列出枚举的所有描述
|
63
|
+
|
64
|
+
## [0.2.0] - 2023-01-19
|
65
|
+
|
66
|
+
### Changed
|
67
|
+
|
68
|
+
- api json序列化改为使用ujson
|
69
|
+
- 移除部分3.10以上的语法
|
70
|
+
|
71
|
+
### Added
|
72
|
+
|
73
|
+
- 日志功能优化改进:
|
74
|
+
- 实现方式更加简洁优雅
|
75
|
+
- 可按照类型去区分
|
76
|
+
- 日志增加打印请求ID
|
77
|
+
- json响应体格式设置为可配置的
|
78
|
+
- 添加ujson包,移除orjson包
|
79
|
+
- 读取蓝图上面的 blueprint.ctx.desc 属性来代替name设置中文tag名
|
80
|
+
- 引入mypy、autoflake等代码检查工具
|
81
|
+
- 添加配置文件基类
|
82
|
+
|
83
|
+
## [0.1.1] - 2022-12-19
|
84
|
+
|
85
|
+
### Changed
|
86
|
+
|
87
|
+
- pip 首页的文件修改
|
88
|
+
|
89
|
+
## [0.1.0] - 2022-12-19
|
90
|
+
|
91
|
+
### Added
|
92
|
+
|
93
|
+
- 接口参数校验
|
94
|
+
- 接口文档生成
|
95
|
+
- 日志使用`loguru`代替
|
96
|
+
- 接口异常拦截
|
97
|
+
- 接口响应统一化
|
File without changes
|
@@ -1,10 +1,38 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.3
|
2
2
|
Name: sanic-api
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.3.0a1
|
4
4
|
Summary: Sanic 框架实用API工具集,拥有自动生成文档、参数校验、配置的导入、日志功能的优化等功能,更好的助力接口的开发
|
5
|
-
|
5
|
+
Project-URL: homepage, https://github.com/x-haose/sanic-api
|
6
|
+
Project-URL: repository, https://github.com/x-haose/sanic-api
|
7
|
+
Project-URL: documentation, https://github.com/x-haose/sanic-api
|
6
8
|
Author-email: 昊色居士 <xhrtxh@gmail.com>
|
7
|
-
|
9
|
+
License: MIT
|
10
|
+
Keywords: Sanic,Sanic扩展,异步
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
12
|
+
Classifier: Intended Audience :: Developers
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
14
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
15
|
+
Classifier: Operating System :: Microsoft :: Windows
|
16
|
+
Classifier: Operating System :: POSIX :: BSD
|
17
|
+
Classifier: Operating System :: POSIX :: Linux
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
21
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
24
|
+
Requires-Python: >=3.10
|
25
|
+
Requires-Dist: hs-config==0.1.3a5
|
26
|
+
Requires-Dist: loguru>=0.7.2
|
27
|
+
Requires-Dist: loki-logger-handler>=0.1.4
|
28
|
+
Requires-Dist: orjson>=3.8.6
|
29
|
+
Requires-Dist: pydantic-settings[toml,yaml]>=2.5.2
|
30
|
+
Requires-Dist: pydantic[dotenv]>=2.9.2
|
31
|
+
Requires-Dist: requests>=2.32.3
|
32
|
+
Requires-Dist: sanic-ext>=23.12.0
|
33
|
+
Requires-Dist: sanic>=23.12.0
|
34
|
+
Requires-Dist: sentry-sdk>=2.17.0
|
35
|
+
Requires-Dist: ujson>=5.7.0
|
8
36
|
Description-Content-Type: text/markdown
|
9
37
|
|
10
38
|

|
@@ -86,4 +114,3 @@ if __name__ == '__main__':
|
|
86
114
|
## 文档
|
87
115
|
|
88
116
|
[文档](https://linktodocumentation)
|
89
|
-
|
@@ -1,79 +1,79 @@
|
|
1
|
-

|
2
|
-
|
3
|
-
[](https://choosealicense.com/licenses/mit/)
|
4
|
-
[]()
|
5
|
-
[](http://www.gnu.org/licenses/agpl-3.0)
|
6
|
-
[](https://github.com/psf/black)
|
7
|
-
|
8
|
-
# Sanic-API
|
9
|
-
|
10
|
-
让您的sanic服务程序更好的支持API文档、参数校验、日志打印、响应规范等
|
11
|
-
|
12
|
-
## 特性
|
13
|
-
|
14
|
-
- 无需任何多余改动,全自动生成openapi文档,使用更加方便
|
15
|
-
|
16
|
-
- 基于`pydantic`的参数校验器,让接口的请求及响应更符合你的预期
|
17
|
-
|
18
|
-
- 使用`loguru`库代替官方`logging`日志库,并对访问日志进行扩展,支持打印接口耗时、接口参数
|
19
|
-
|
20
|
-
- 使用`{code: 0, data: null, msg: ""}`样式的接口返回
|
21
|
-
|
22
|
-
- 对接口中的异常进行拦截,及自定义错误码
|
23
|
-
|
24
|
-
- 接口返回样式可自定义配置
|
25
|
-
|
26
|
-
## 截图
|
27
|
-
|
28
|
-
## 路线图
|
29
|
-
|
30
|
-
- 增加一键生成预设项目cli命令
|
31
|
-
|
32
|
-
- 编写详细文档
|
33
|
-
|
34
|
-
- API接口增加请求头、URL路径参数收集和校验:
|
35
|
-
|
36
|
-
## 安装
|
37
|
-
|
38
|
-
使用 pip 安装 sanic-api
|
39
|
-
|
40
|
-
```bash
|
41
|
-
pip install sanic-api
|
42
|
-
```
|
43
|
-
|
44
|
-
## 使用方法/示例
|
45
|
-
|
46
|
-
```python
|
47
|
-
from sanic import Sanic, text
|
48
|
-
from sanic_api import init_api
|
49
|
-
|
50
|
-
app = Sanic("Sanic-API")
|
51
|
-
|
52
|
-
|
53
|
-
@app.get('/')
|
54
|
-
async def index(request):
|
55
|
-
return text("Sanic-API Example")
|
56
|
-
|
57
|
-
|
58
|
-
def main():
|
59
|
-
init_api(app)
|
60
|
-
app.run(access_log=True)
|
61
|
-
|
62
|
-
|
63
|
-
if __name__ == '__main__':
|
64
|
-
main()
|
65
|
-
|
66
|
-
```
|
67
|
-
|
68
|
-
## 开发
|
69
|
-
|
70
|
-
要部署这个项目,请运行
|
71
|
-
|
72
|
-
```bash
|
73
|
-
pip install pdm
|
74
|
-
pdm sync
|
75
|
-
```
|
76
|
-
|
77
|
-
## 文档
|
78
|
-
|
79
|
-
[文档](https://linktodocumentation)
|
1
|
+

|
2
|
+
|
3
|
+
[](https://choosealicense.com/licenses/mit/)
|
4
|
+
[]()
|
5
|
+
[](http://www.gnu.org/licenses/agpl-3.0)
|
6
|
+
[](https://github.com/psf/black)
|
7
|
+
|
8
|
+
# Sanic-API
|
9
|
+
|
10
|
+
让您的sanic服务程序更好的支持API文档、参数校验、日志打印、响应规范等
|
11
|
+
|
12
|
+
## 特性
|
13
|
+
|
14
|
+
- 无需任何多余改动,全自动生成openapi文档,使用更加方便
|
15
|
+
|
16
|
+
- 基于`pydantic`的参数校验器,让接口的请求及响应更符合你的预期
|
17
|
+
|
18
|
+
- 使用`loguru`库代替官方`logging`日志库,并对访问日志进行扩展,支持打印接口耗时、接口参数
|
19
|
+
|
20
|
+
- 使用`{code: 0, data: null, msg: ""}`样式的接口返回
|
21
|
+
|
22
|
+
- 对接口中的异常进行拦截,及自定义错误码
|
23
|
+
|
24
|
+
- 接口返回样式可自定义配置
|
25
|
+
|
26
|
+
## 截图
|
27
|
+
|
28
|
+
## 路线图
|
29
|
+
|
30
|
+
- 增加一键生成预设项目cli命令
|
31
|
+
|
32
|
+
- 编写详细文档
|
33
|
+
|
34
|
+
- API接口增加请求头、URL路径参数收集和校验:
|
35
|
+
|
36
|
+
## 安装
|
37
|
+
|
38
|
+
使用 pip 安装 sanic-api
|
39
|
+
|
40
|
+
```bash
|
41
|
+
pip install sanic-api
|
42
|
+
```
|
43
|
+
|
44
|
+
## 使用方法/示例
|
45
|
+
|
46
|
+
```python
|
47
|
+
from sanic import Sanic, text
|
48
|
+
from sanic_api import init_api
|
49
|
+
|
50
|
+
app = Sanic("Sanic-API")
|
51
|
+
|
52
|
+
|
53
|
+
@app.get('/')
|
54
|
+
async def index(request):
|
55
|
+
return text("Sanic-API Example")
|
56
|
+
|
57
|
+
|
58
|
+
def main():
|
59
|
+
init_api(app)
|
60
|
+
app.run(access_log=True)
|
61
|
+
|
62
|
+
|
63
|
+
if __name__ == '__main__':
|
64
|
+
main()
|
65
|
+
|
66
|
+
```
|
67
|
+
|
68
|
+
## 开发
|
69
|
+
|
70
|
+
要部署这个项目,请运行
|
71
|
+
|
72
|
+
```bash
|
73
|
+
pip install pdm
|
74
|
+
pdm sync
|
75
|
+
```
|
76
|
+
|
77
|
+
## 文档
|
78
|
+
|
79
|
+
[文档](https://linktodocumentation)
|
File without changes
|
@@ -0,0 +1,56 @@
|
|
1
|
+
from pydantic import BaseModel, Field
|
2
|
+
from sanic import Blueprint, Sanic, json
|
3
|
+
from sanic.log import logger
|
4
|
+
|
5
|
+
from sanic_api.api import BaseRespTml, Request
|
6
|
+
from sanic_api.app import BaseApp
|
7
|
+
|
8
|
+
user_blueprint = Blueprint("user", "/user")
|
9
|
+
|
10
|
+
|
11
|
+
class UserInfoModel(BaseModel):
|
12
|
+
user_id: int = Field(title="用户ID")
|
13
|
+
|
14
|
+
|
15
|
+
class UserInfoResponse(BaseRespTml):
|
16
|
+
user_name: str = Field(title="用户名")
|
17
|
+
|
18
|
+
|
19
|
+
class UseLoginRequest(Request):
|
20
|
+
form_data: UserInfoModel
|
21
|
+
|
22
|
+
|
23
|
+
@user_blueprint.post("info")
|
24
|
+
async def user_info(request: Request, json_data: UserInfoModel):
|
25
|
+
"""
|
26
|
+
获取用户信息
|
27
|
+
"""
|
28
|
+
logger.info(f"data: {json_data}")
|
29
|
+
info = UserInfoResponse(user_name="张三")
|
30
|
+
info.temp_data.code = "0000"
|
31
|
+
info.temp_data.msg = "查询成功"
|
32
|
+
return info.resp()
|
33
|
+
|
34
|
+
|
35
|
+
@user_blueprint.post("login")
|
36
|
+
async def user_login(request: UseLoginRequest):
|
37
|
+
"""
|
38
|
+
用户登录
|
39
|
+
"""
|
40
|
+
logger.info(f"user_id: {request.form_data.user_id}")
|
41
|
+
return json(request.form_data.model_dump())
|
42
|
+
|
43
|
+
|
44
|
+
class App(BaseApp):
|
45
|
+
"""
|
46
|
+
服务示例
|
47
|
+
"""
|
48
|
+
|
49
|
+
async def setup_route(self, app: Sanic):
|
50
|
+
api = Blueprint.group(url_prefix="api")
|
51
|
+
api.append(user_blueprint)
|
52
|
+
app.blueprint(api)
|
53
|
+
|
54
|
+
|
55
|
+
if __name__ == "__main__":
|
56
|
+
App.run()
|