问题描述
我有一个基本的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
方法: