With Flask-Restplus how to create a POST api without making the URL same with GET

喜你入骨 提交于 2019-12-01 13:06:59

问题


I'm new to Flask and Flask-RestPlus. I'm creating a web api where I want keep my POST urls different from the GET urls which are visible in Swagger. For example in Flask-Restplus

@api.route('/my_api/<int:id>')
class SavingsModeAction(Resource):
    @api.expect(MyApiModel)
    def post(self):
        pass #my code goes here

    def get(self, id):
        pass #my code goes here

So in swagger for the both apis url would look like

GET: /my_api/{id}

POST: /my_api/{id}

But so far I have absolutely no use of {id} part in my post api and it perhaps creates a bit of confusion for an user whether to update an existing record or to create a new, however the purpose of the api is just to create.

来源:https://stackoverflow.com/questions/57448609/with-flask-restplus-how-to-create-a-post-api-without-making-the-url-same-with-ge

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