question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Axios request config params object

See original GitHub issue

Hi, how can i use Axios request config params object for Resource object actions? Action of Resource object has function pathFn for adding some parameters to the URL, but i need add some handy parameters with stringifying needing and Axios has paramsSerializer function for that (usable with Qs library). Please, how can i use Axios paramsSerializer function with your helper?

Resource object wrapper with configured Axios instance and paramsSerializer option:

import Qs from 'qs'
import Axios from 'axios'
import { Resource } from 'vuex-rest-api'

export default class ResourceWrapper {
    constructor(baseURL = null, options = {}) {
        baseURL = baseURL || 'http://localhost:8003/api/admin'
        options.axios = Axios.create({
            paramsSerializer: function(params) {
                return Qs.stringify(params, {arrayFormat: 'indices'})
            }
        })

        return new Resource(baseURL, options)
    }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
christianmalekcommented, Apr 7, 2017

Maybe, params object should not be set if requestConfig object is not contain paramsSerializer function.

Great idea. I’ll change this tomorrow and let you know!

Then will be better specify paramsSerializer in the ResourceWrapper

If I add the check constraint it is indifferent if you just do it on one action or the axios instance.

0reactions
elcekacommented, Apr 7, 2017

Thank you again, it is working, all is only about implementation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Request Config | Axios Docs
These are the available config options for making requests. ... `params` are the URL parameters to be sent with the request // Must...
Read more >
Use Axios.Get with params and config together - Stack Overflow
Axios takes the entire config in the second argument, not a list of config objects. Put the params inside the config, and pass...
Read more >
Axios Cheat Sheet - Kapeli - Dash for macOS
Make a request for a user with a given ID axios.get('/user? ... be sent with the request // Must be a plain object...
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 >
Understanding Axios GET requests - LogRocket Blog
Learn how to make GET requests in Axios with query parameters and API keys, plus concurrent and HEAD requests and error handling.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found