Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/007gzs/tornado-rest-framework
Web APIs for Tornado
https://github.com/007gzs/tornado-rest-framework
Last synced: 2 months ago
JSON representation
Web APIs for Tornado
- Host: GitHub
- URL: https://github.com/007gzs/tornado-rest-framework
- Owner: 007gzs
- License: gpl-3.0
- Created: 2018-06-09T15:31:38.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-01-28T02:01:54.000Z (almost 4 years ago)
- Last Synced: 2024-10-12T15:44:08.111Z (3 months ago)
- Language: Python
- Size: 109 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
######################
Tornado REST framework
######################.. image:: https://travis-ci.org/007gzs/tornado-rest-framework.svg?branch=master
:target: https://travis-ci.org/007gzs/tornado-rest-framework
.. image:: https://img.shields.io/pypi/v/tornadoapi.svg
:target: https://pypi.org/project/tornadoapiTornado REST framework
`【阅读文档】 `_。
安装
---------------------
目前 tornadoapi 支持的 Python 环境有 2.7, 3.4, 3.5, 3.6 和 pypy。::pip install tornadoapi
快速开始
_____________________启动之前或启动脚本开始时配置环境变量 并执行setup初始化::
os.environ.setdefault("TORNADOAPI_SETTINGS_MODULE", "config.settings")
import tornadoapi
tornadoapi.setup()config/settings.py 中增加自定义配置::
DEBUG = True
TEST = 1通过以下代码可以获取到settings参数::
from tornadoapi.conf import settings
settings.TEST
ApiHandler调用示例::
from tornadoapi.handler import ApiHandler
class TestHandler(ApiHandler):
test_param = fields.CharField(description='测试参数', default=None)
test_choice = fields.ChoiceField(description='选择参数', default=None, choices=((0, '选项0'), (1, '选项1')))@classmethod
def get_return_sample(cls):
return ErrCode.SUCCESS.get_res_dict(data={'test_param': '测试参数', 'test_choice' :'选择参数'})@classmethod
def get_handler_name(cls):
return '测试'def get(self, *args, **kwargs):
ret = {
'test_param': self.test_param,
'test_choice': self.test_choice
}
self.write_api(ret)示例项目
---------------------`demo `_