I’ve tried to post using:
getHomes: function(){
var token = this.methods.localstoreout('token').access;
this.request.post(
'https://app.mysite.io/api/homes/', {
headers: {
'Authorization': 'Token '+token
},
},
......
This will send data through multipart/form-data, i can’t easily access these fields, as Django Rest Framework makes it difficult without using a middleware for the effect.
In order to customize the request’s header i tried this:
Defining a method:
authHeader: function(){
this.request.setup({
beforeSend: function () {
xhr.setRequestHeader ('Authorization', 'Token '+this.methods.localstoreout('token').access);
}
});
},
and in another method:
this.methods.authHeader();
this.request.post(
'https://app.cleverway.io/api/homes/', {},
//success
function (data, status, xhr) {
console.log('Homes list: '+ data);
.......
Firstly, xhr is not defined when i call it, although the app object is already instantiated . Do i need to define it like app.request.setup()?
Secondly, it seems like this setup is permanent, i’d need to remove auth headers everytime i call the authHeader method.
Is there an all in one solution, where beforesend is called within the post method?