Skip to content

Commit 4897de8

Browse files
committed
add restful api standard
1 parent e5e14eb commit 4897de8

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

‎python-note/flaskapi.rst‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,53 @@
44
用来测试接口的 flask server
55
========================================
66

7+
Restful规范
8+
___________________________________
9+
10+
.. code-block:: python
11+
12+
"""
13+
RESTFul url 规范,参考:http://www.pythondoc.com/flask-restful/second.html
14+
15+
========== =============================================== =============================
16+
HTTP 方法 URL 动作
17+
========== =============================================== ==============================
18+
GET http://[hostname]/todo/api/v1.0/tasks 检索任务列表
19+
GET http://[hostname]/todo/api/v1.0/tasks/[task_id] 检索某个任务
20+
POST http://[hostname]/todo/api/v1.0/tasks 创建新任务
21+
PUT http://[hostname]/todo/api/v1.0/tasks/[task_id] 更新任务
22+
DELETE http://[hostname]/todo/api/v1.0/tasks/[task_id] 删除任务
23+
========== ================================================ =============================
24+
25+
26+
命名规范:
27+
28+
# 我们使用 SomeListHandler 命名而不是复数形式方便区分,比如 VideosHandler 和 VideoHandler 不容易区分
29+
"""
30+
class TaskListHandler(BaseHandler):
31+
def get(self):
32+
"""获取列表"""
33+
pass
34+
35+
def post(self):
36+
"""创建一条新的记录"""
37+
pass
38+
39+
40+
class TaskHandler(BaseHandler):
41+
def get(self, _id):
42+
"""获取一条记录的信息"""
43+
pass
44+
45+
def put(self, _id):
46+
"""更新一条记录的信息"""
47+
pass
48+
49+
def delete(self, _id):
50+
"""删除一条记录"""
51+
pass
52+
53+
754
测试 server
855
___________________________________
956

@@ -88,3 +135,6 @@ ___________________________________
88135
89136
if __name__ == '__main__':
90137
app.run(debug=True) # port=5000
138+
139+
140+

0 commit comments

Comments
 (0)