I have a basic flask-restx
app (main.py
) as follows:
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
As it can be seen in the code, I am calling both GET
& POST
methods on the route: /greetings/restx/hello/
. I have deployed this code on API Gateway
and lambda
using Serverless
.
The serverless.yml
file:
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
On the API Gateway
, when I test the GET
& POST
methods separately from the dashboard, they print their respective outputs.
Screenshot of the GET
method
Screenshot of the POST
method
I have the following URL for this service: https://abcdefgh.execute-api.eu-central-1.amazonaws.com/dev/{proxy+}.
When I invoke the URL itself from the browser as: https://abcdefgh.execute-api.eu-central-1.amazonaws.com/dev/greetings/restx/hello/?name=Alex it always calls the GET
method as follows:
The POST
method is never being invoked. What is the mistake that I am doing?
On browser, it always use GET
method.
For POST
method, you can use POSTMAN tool at: https://www.postman.com
Or use curl
on terminal:
curl -X POST url