-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdemo_bottle.py
More file actions
62 lines (52 loc) · 1.99 KB
/
demo_bottle.py
File metadata and controls
62 lines (52 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from bottle import route, run, template, request,HTTPResponse
from src.api_shop import ApiShop
conf = [
{
'url': 'weixin/login',
'class': 'business_code.test.abc.api_login',
'name': '微信账户登录',
'methods': {
'POST': [
{'name': 'username', 'type': str, 'required': True,
'min': 3, 'max': 24, 'description': '用户名'},
{'name': 'ddd', 'type': str, 'description': '日期'},
]
}
},
{
'url': 'weixin/<name>/<id>',
'class': 'business_code.views.test',
'name': '账户登录',
'methods': {
'POST': [{'name': 'id', 'type': bool, 'required': True,
'description': '用户id'},
{'name': 'name', 'type': str, 'min':4,'required': True,
'description': '用户name'},
],
}
},
]
af = ApiShop(conf,
{
'lang': 'zh',
'name_classification': ['微信', '账户'],
'url_classification': ['weixin', 'login'],
'auto_create_folder': True, # 自动创建文件夹
'auto_create_file': True, # 自动创建文件
'auto_create_class': True, # 自动创建类
'auto_create_method': True, # 自动创建方法
'framework':'bottle'
})
from src.api_shop import get_api_result_json
from business_code.test.abc import api_login
# get_api_result_json(api_class, method, data=None, request=None, not200=True)
print('----->', get_api_result_json(api_login, 'POST'))
@route('/api/<url:re:([\s\S]*)>',['GET','PUT','PATCH','DELETE','POST'])
def api_index(url):
print('*'*20,url)
if url == 'document/':
return af.render_documents(request, url)
if url == 'api_data':
return af.get_api_data(request, url)
return af.api_entry(request, url)
run(host='localhost', port=8080,reloader=True,debug=True)