Passing array in query via axios
See original GitHub issueHi,
I’m using axios to send a GET request to my flask-smorest endpoint. I know there’s no real agreement on this spec-wise, but the request’s querystring contains an array, and axios sends it in this format:
http://127.0.0.1:5000/api/v1/items/?types[]=cd&types[]=dvd
I’ve defined the schema used for reading the arguments as
class FilterSchema(ma.Schema):
...
types = ma.fields.List(ma.fields.String(), missing=[])
Yet when I try to read the data received in my endpoint, types is empty:
@items_blp.route('/')
class ItemCollection(MethodView):
@items_blp.arguments(FilterSchema(unknown=ma.EXCLUDE), location="query")
@listings_blp.response(ItemSchema(many=True))
def get(self, payload):
# payload['types'] is empty...
if payload['types']:
qs = Item.objects.filter(item_type__in=payload['types'])
return qs
Is this a missing feature in flask-smorest or should I ask on SO whether I should use another way to pass data?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How to correctly use axios params with arrays - Stack Overflow
I got using "paramSerializer" a bit confuse. Before looking for the "right way" to use axios with array querystring on Google, ...
Read more >Providing an array as a param isn't working as expected. #604
I want to put in the following get request using axios config.params object: https://api.nal.usda.gov/ndb/nutrients/?format=json&api_key=...
Read more >Sending Array Of Objects in GET request (axios) - Reddit
For filter values i have to send array of objects in parameters. Now I know when we want to send complex params in...
Read more >GET Request Query Params with Axios - Mastering JS
The easiest way to make a GET request with Axios is the axios.get() function. The 2nd parameter to axios.get() is the Axios options:...
Read more >Request Config | Axios Docs
It can be convenient to set `baseURL` for an instance of axios to pass relative ... 'PATCH' and 'DELETE' // The last function...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just FYI, you can configure axios to not do this
[]
nonsense that started in PHP when they thought it’d be even remotely a good idea to let the client decide whether unstructured form data should become an array or not…Just pass
paramsSerializer: params => qs.stringify(params, {arrayFormat: 'repeat'})
to your axios calls (or better: useaxios.create()
to create an instance where you pass this as a setting and use that instance everywhere)There’s two issues
1/ is a webargs issue, so I’ll transfer to webargs. You’ll have to write a custom parser (see https://webargs.readthedocs.io/en/latest/advanced.html#custom-parsers).
2/ is an apispec issue. I’m not sure there’s a way to write a spec that will display correctly in a frontend such as ReDoc or Swagger-UI, so you might end up just adding a generic comment at the beginning of the spec.