如何解决未从API Gateway中的URL调用POST方法
我有一个基本的flask-restx
应用(main.py
),如下所示:
ns = Namespace(
"greetings",description="Get Greetings."
)
parser = reqparse.RequestParser()
parser.add_argument("name",type=str,help="name")
@ns.route('/restx/hello/')
class restx_hello(Resource):
@ns.expect(parser,validate=True)
def get(self):
args = parser.parse_args()
name = args['name']
g = 'Greetings to you!'
return 'Hello ' + name + '! I am from restx. ' + g
@ns.expect(parser,validate=True)
def post(self):
args = parser.parse_args()
name = args['name']
return 'This is the POST method,' + name
从代码中可以看出,我正在GET
路由上同时调用POST
和/greetings/restx/hello/
方法。我已经使用API Gateway
在lambda
和Serverless
上部署了此代码。
serverless.yml
文件:
service: flask-api
provider:
name: aws
runtime: python3.7
functions:
app:
handler: wsgi_handler.handler
events:
- http: ANY /
- http: 'ANY {proxy+}'
custom:
wsgi:
app: app.app
pythonBin: python3
packRequirements: false
pythonRequirements:
dockerizePip: non-linux
plugins:
- serverless-wsgi
- serverless-python-requirements
在API Gateway
上,当我从仪表板分别测试GET
和POST
方法时,它们将打印各自的输出。
GET
方法的屏幕截图
POST
方法的屏幕截图
我对此服务有以下URL:https://abcdefgh.execute-api.eu-central-1.amazonaws.com/dev/{proxy+}。
当我通过浏览器以https://abcdefgh.execute-api.eu-central-1.amazonaws.com/dev/greetings/restx/hello/?name=Alex的形式调用URL本身时,它总是按以下方式调用GET
方法:
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。