|
@@ -6,7 +6,7 @@
|
|
## Usage
|
|
## Usage
|
|
|
|
|
|
```
|
|
```
|
|
-from flask import Flask
|
|
|
|
|
|
+from flask import Flask, request
|
|
from flask_restful import Resource, Api
|
|
from flask_restful import Resource, Api
|
|
|
|
|
|
app = Flask(__name__)
|
|
app = Flask(__name__)
|
|
@@ -17,11 +17,22 @@ class HelloWorld(Resource):
|
|
|
|
|
|
# 覆写get,post等方法处理 HTTP 请求
|
|
# 覆写get,post等方法处理 HTTP 请求
|
|
def get(self):
|
|
def get(self):
|
|
- return {'hello': 'world'}
|
|
|
|
-
|
|
|
|
-api.add_resource(HelloWorld, '/')
|
|
|
|
|
|
+ data = request.json
|
|
|
|
+ return {'hello': 'world'+ data.get("id") }
|
|
|
|
+
|
|
|
|
+ def post(self):
|
|
|
|
+ data = request.json
|
|
|
|
+ return {'hello': 'world'+ data.get("id") }
|
|
|
|
+
|
|
|
|
+ def delete(self):
|
|
|
|
+ data = request.json
|
|
|
|
+ return {'hello': 'world'+ data.get("id") }
|
|
|
|
+
|
|
|
|
+api.add_resource(HelloWorld, '/hello')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
app.run(debug=True)
|
|
app.run(debug=True)
|
|
|
|
|
|
```
|
|
```
|
|
|
|
+然后访问:http://localhost/hello?id=11
|
|
|
|
+
|