I have a Flask_restful resource which I am adding as blueprint resource
class SampleAPI(Resource):
def __init__(self):
self.reqparse = reqparse.RequestParser(bundle_errors=True)
self.reqparse.add_argument('name', type=str, required=False,
help='No name provided',
location='json')
self.reqparse.add_argument('id', type=str, required=False,
help='No id provided',
location='args')
def post(self):
args = self.reqparse.parse_args()
name = args["name"]
# Do something with name
return lf.to_json(), 201
def get(self):
args = self.reqparse.parse_args()
ID = args["id"]
# Do something with ID
return lf.to_json(), 200
When I use post endpoint, every works fine as I am sending a JSON body with request. BUT when I make a GET request, I get a bad request error -
{
"message": "The browser (or proxy) sent a request that this server could not understand."
}
I found out that, I need to send an empty JSON body - "{}" with the request to make the request working otherwise it throws the bad request error as above.
I need to understand how I can allow no body
but also use reqparse.RequestParser
and parse arguments using flask_restful extension of flask in this GET request!
Thanks!