I've developed an API with django rest framework, my frontend is built in vue js, so I have to use fetch to communicate with the API.
function apiService(endpoint, method, data) {
const config = {
method: method || 'GET',
body: data !== undefined ? JSON.stringify(data) : null,
headers: {
'content-type': 'application/json',
'X-CSRFToken': CSRF_TOKEN
}
};
return fetch(endpoint, config)
.then(data => getJson(data))
.catch(err => err)
};
I've noticed that this code works properly, but I have a doubt on the fact that, because I've added the authentication permission on the api, I would have to send a token in the request, because I'm not conneccting from a browser. So, how this token is send to the api, if I don't send it.