Flask restful API urls

♀尐吖头ヾ 提交于 2019-12-11 11:46:17

问题


I am using Flask-RESTful(http://flask-restful.readthedocs.org/en/latest/index.html) in my project. Afrer reading some examples I understood that I will have only get, post, update etc methods in my Resource class. How can I make my own Resource class method with a unique url like it was in Flask with @app.route() decorator? Thanks.


回答1:


Look at quick start (A Minimal API, Resourceful Routing and etc.):

api.add_resource(HelloWorld, '/')

api.add_resource(TodoSimple, '/<string:todo_id>')



回答2:


I hope it helps

@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'GET':
        pass
    elif request.method == 'POST':
        pass
    else:
        pass


来源:https://stackoverflow.com/questions/19636532/flask-restful-api-urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!