Home > Mobile >  How do a request get with axios passing params?
How do a request get with axios passing params?

Time:11-05

I want to send params from react to expressjs, i am using axios method get

const searchQuery = 'any' 
let users = await axios.get('http://localhost:3000/v1/users/search', {params:{data:searchQuery}})

and in my backend

router.get('/search/:query', UserController.searchUsers);


static async searchUsers(req, res) {
    const { searchQuery } = req.params
    console.log('searchQuery',req.params, searchQuery)

i am getting this:

/v1/users/search?data=ddas

what i am doing wrong?

CodePudding user response:

let users = await axios.get('http://localhost:3000/v1/users/search', {params:{data:searchQuery}})

your query parameter is data.
To access it in your backend

const { data } = req.query;
  • Related