I am using React in the frontend and Django in the backend and I am currently doing the API integration for which I am using Axios.
So in the frontend side I am calling a URL like this
http://localhost:3000/attempt/?quiz_id=6
and I want the quiz_id = 6 so that I can use this afterward to access data in the backend.
I am using Functional components if that helps.
You can take a look at axios's documentation in github
If what you want to do is a GET request this should be enough:
axios.get('http://localhost:3000/attempt/?quiz_id=6')
.then((res) => {
// handle success
console.log(res);
})
Also you have available this kind of usage:
axios.get('http://localhost:3000/attempt', {
params: {
quiz_id: 6
}
}).then((res) => {
// handle success
console.log(res);
});
You can use this too:
const data = await axios.get('http://localhost:3000/attempt/?quiz_id=6').then(res => res.data);
You can include dynamic quiz_id by using params. The way for this is to making an axios request using the id of the param that you want to update and return:
Your code will read like so:
axios.get('http://localhost:3000/attempt/${quiz_id}', quiz_id);