There are no items in your cart
Add More
Add More
Item Details | Price |
---|
Thu Jan 5, 2023
In Axios, you can send query string parameters in a GET, PUT, POST, DELETE or any other request by appending them to the URL as key-value pairs. You can use the params
option in the axios.get(url, config)
, axios.post(url, data, config)
, axios.put(url, data, config)
, axios.delete(url, config)
and other methods to pass an object containing the query string parameters.
Here's an example of how to send query string parameters using Axios in a GET request:
axios.get('https://example.com/search', { params: { q: 'querystring', sort: 'asc' } }) .then(response => { console.log(response.data); }).catch(error => { console.log(error); });
This will make a GET request to 'https://example.com/search?q=querystring&sort=asc'
Here's an example of how to send query string parameters using Axios in a PUT request:
axios.put('https://example.com/api/resource', { data: { name: 'example' } }, { params: { q: 'querystring', sort: 'asc' } }) .then(response => { console.log(response.data); }) .catch(error => { console.log(error); });
This will make a PUT request to 'https://example.com/api/resource?q=querystring&sort=asc' with the data {name: 'example'} in the body of the request.
It's worth noting that depending on the API you are working with, it may or may not accept query string parameters in specific requests. Some APIs may require query string parameters to be passed in the request body instead.
DCT Academy
Full Stack web development training institute in Bangalore