简体   繁体   English

Flask Restful API网址

[英]Flask restful API urls

I am using Flask-RESTful( http://flask-restful.readthedocs.org/en/latest/index.html ) in my project. 我在我的项目中使用Flask-RESTful( http://flask-restful.readthedocs.org/en/latest/index.html )。 Afrer reading some examples I understood that I will have only get, post, update etc methods in my Resource class. 阅读一些示例后,我了解到我的Resource类中只有get,post,update等方法。 How can I make my own Resource class method with a unique url like it was in Flask with @app.route() decorator? 如何使用独特的网址制作自己的Resource类方法,就像使用@ app.route()装饰器在Flask中那样? Thanks. 谢谢。

Look at quick start ( A Minimal API , Resourceful Routing and etc.): 看一下快速入门( 最小的API资源丰富的路由等):

api.add_resource(HelloWorld, '/')

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

I hope it helps 希望对您有所帮助

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM