Skip to content

Using flask-restx for nameless input arguments #491

@jedrek-VL

Description

@jedrek-VL

Hi, I am using flask-restx to build an app which receives a JSON-formatted string via a POST request. Currently, the relevant piece of code in the app reads:

api = Api(app, authorizations=authorizations, security='bearerToken')
request_parser = api.parser()
request_parser.add_argument('input_data', location='json', required=True)

This correctly handles requests of the form:

curl  -d '{"input_data": [0.0, 0.5, 1.0]}' -H "Content-Type: application/json" …

and Swagger documentation is generated correctly.

However, I would like the app to respond to simpler requests like:

curl  -d '[0.0, 0.5, 1.0]' -H "Content-Type: application/json" …

and still have correct Swagger documentation. I know how to do it just by calling request.get_json(), but I'd prefer to use flask-restx. I've gone through the flask-restx docs but couldn't see how to do it. Any pointers will be greatly appreciated :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions