In my Emberjs application, I have an Employee model that I have to load through a REST Get API call, where I must first authenticate the API for the token and then start loading the data, I know how to do it with jQuery, but I donβt know how I can implement this in EmberJS, so I will be very grateful if anyone can teach me how to do this.
Below is the jQuery code that I use for authentication, retrieving employee data, as well as EmberJS model code
thank
Authentication:
$.ajax
({
type: "POST",
url: "http://portal.domainname.com/auth",
dataType: 'json',
async: false,
data: JSON.stringify({
Login: "logmein@email.com",
Password : "test"
}),
success: function(data) {
console.log(data);
},
error: function(xhr, error){
console.debug(xhr); console.debug(error);
}
});
Allows you to download employee data:
$.ajax ({
type: "GET",
url: "http://portal.domainname.com/employees",
dataType: 'json',
async: false,
beforeSend: function (xhr) {
xhr.setRequestHeader ("Token", "0000000-0000-0000-0000-00000000");
},
success: function(data) {
console.log(data);
},
error: function(xhr, error){
console.debug(xhr); console.debug(error);
} });
Model EmberJS
App.Store = DS.Store.extend({
revision: 11
});
App.Employee = DS.Model.extend({
employeeID: DS.attr('string'),
employeeName: DS.attr('string')
});
App.Store.reopen({
adapter: 'DS.RESTAdapter'
});
Mchan source
share