RESTful API 扩展 https://github.com/flask-restful/flask-restful

天问 61ba8d265d Update 'README.md' 1 month ago
README.md 61ba8d265d Update 'README.md' 1 month ago

README.md

flask_restful

为 Flask 框架提供支持的 RESTful API 扩展

Usage

from flask import Flask, request
from flask_restful import Resource, Api

app = Flask(__name__)
api = Api(app)

# 接口需要继承 Resource 类
class HelloWorld(Resource):
    
    # 覆写get,post等方法处理 HTTP 请求
    def get(self):
        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__':
    app.run(debug=True)

然后访问:http://localhost/hello?id=11