我有一个基本的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+}。
当我从浏览器调用 URL 本身时:https://abcdefgh.execute-api.eu-central-1.amazonaws.com/dev/greetings/restx/hello/?name=Alex它总是调用GET
如下方法:
该POST
方法永远不会被调用。我在做什么错误?