-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use 'form' location and process request as json? #594
Comments
Flask puts form data in a different place in the However, you have set up a request parser here but you don't currently use it. So you should be able to use it to retrieve the values regardless of location passed to your code. Something like: parser = api.parser()
parser.add_argument('title', type=str, help='Some param', required=True, location=('form', 'json'))
parser.add_argument('content', type=str, help='Some param', required=True, location=('form', 'json'))
@api.route('/send')
class Send(Resource):
@api.doc(parser=parser, validate=True)
def post(self, **kwargs):
input_args = parser.parse_args() # This returns a dictionary containing the parsed values from the specified locations.
print(f"Title: {input_args['title']}")
print(f"Content: {input_args['content']}") |
So, if I use
This is the output I wish to have: CURL curl -X 'POST' \
'http://localhost:5000/send \
-H 'accept: application/json' \
-d '{"title":"test", "content":"test"}' Request URL http://localhost:5000/send I know I can have this by set |
@sandyboxy, try with |
Hi @kartikeyporwal, curl -X 'POST' \
'http://localhost:5000/send' \
-H 'accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'title=test&content=test' instead of having the following: curl -X 'POST' \
'http://localhost:5000/send' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"title": "string",
"content": "string"
}' |
Why you need the json when you are specifying the params as form? If you need to pass json then specify
|
Simply I wish to use swagger/flask-api to show a simplified page to test API (using |
Ask a question
How to use 'form' location and process request as json?
Additional context
I wish to use form field to allow users to test my API by filling field instead of to fill a raw JSON dict.
This is my relevant code:
when I set field
location='form'
I have the form with fields to fill but the request isbut I wish to have the following output without to set
location='json'
The text was updated successfully, but these errors were encountered: