jeudi 12 février 2015

Calling HTTP method GET form an asp.net web api with ember

I'm building an api in asp.net and I'm trying to call it with ember... what I'm trying to get to work right now is the simple GET (find all)


the output from postman (chrome extension for testing apis) gives me this:



[
{
"Id": 1,
"Name": "psilva",
"Project": "a",
"Objectives": "s",
"City": "a",
"Country": "s",
"EventStart": "2015-02-06T11:06:23.673",
"Departure": "2015-02-06T11:06:23.673",
"Arrival": "2015-02-06T11:06:23.673",
"Registration": "a",
"NationalTransportation": "a",
"Accommodation": "a",
"AcNumberNights": 1,
"AcPreferHotel": "a",
"AcPreferHotelUrl": "a",
"Flight": "a",
"FlDeparture": "2015-02-06T11:06:23.673",
"FlDepartPrefer": "a",
"FlDepartPreferUrl": "a",
"FlReturn": "2015-02-06T11:06:23.673",
"FlRetPrefer": "a",
"FlRetPreferUrl": "a",
"Notes": "a",
"Files": "a",
"Status": "a"
},
{
"Id": 2,
"Name": "psilva",
"Project": "a",
"Objectives": "s",
"City": "a",
"Country": "s",
"EventStart": "2015-02-06T11:06:23.673",
"Departure": "2015-02-06T11:06:23.673",
"Arrival": "2015-02-06T11:06:23.673",
"Registration": "a",
"NationalTransportation": "a",
"Accommodation": "a",
"AcNumberNights": 1,
"AcPreferHotel": "a",
"AcPreferHotelUrl": "a",
"Flight": "a",
"FlDeparture": "2015-02-06T11:06:23.673",
"FlDepartPrefer": "a",
"FlDepartPreferUrl": "a",
"FlReturn": "2015-02-06T11:06:23.673",
"FlRetPrefer": "a",
"FlRetPreferUrl": "a",
"Notes": "a",
"Files": "a",
"Status": "a"
},
{
"Id": 3,
"Name": "psilva",
"Project": "a",
"Objectives": "s",
"City": "a",
"Country": "s",
"EventStart": "2015-02-06T11:06:23.673",
"Departure": "2015-02-06T11:06:23.673",
"Arrival": "2015-02-06T11:06:23.673",
"Registration": "a",
"NationalTransportation": "a",
"Accommodation": "a",
"AcNumberNights": 1,
"AcPreferHotel": "a",
"AcPreferHotelUrl": "a",
"Flight": "a",
"FlDeparture": "2015-02-06T11:06:23.673",
"FlDepartPrefer": "a",
"FlDepartPreferUrl": "a",
"FlReturn": "2015-02-06T11:06:23.673",
"FlRetPrefer": "a",
"FlRetPreferUrl": "a",
"Notes": "a",
"Files": "a",
"Status": "a"
},
{
"Id": 5,
"Name": "psilva",
"Project": "a",
"Objectives": "s",
"City": "a",
"Country": "s",
"EventStart": "2015-02-06T11:06:23.673",
"Departure": "2015-02-06T11:06:23.673",
"Arrival": "2015-02-06T11:06:23.673",
"Registration": "a",
"NationalTransportation": "a",
"Accommodation": "a",
"AcNumberNights": 1,
"AcPreferHotel": "a",
"AcPreferHotelUrl": "a",
"Flight": "a",
"FlDeparture": "2015-02-06T11:06:23.673",
"FlDepartPrefer": "a",
"FlDepartPreferUrl": "a",
"FlReturn": "2015-02-06T11:06:23.673",
"FlRetPrefer": "a",
"FlRetPreferUrl": "a",
"Notes": "a",
"Files": "a",
"Status": "a"
}
]


which means the api is working but calling it ember returns empty... I've been reading about this and what I think I have to do is tweak the serializer and RESTAdapter, but I'm not sure how to use this... any ideas?


here's the ember code:


model:



App.Event = DS.Model.extend({
Name: DS.attr('string'),
Project: DS.attr('string'),
Objectives: DS.attr('string'),
City: DS.attr('string'),
Country: DS.attr('string'),
EventStart: DS.attr('isodate'),
Departure: DS.attr('isodate'),
Arrival: DS.attr('isodate'),
Registration: DS.attr('string'),
NationalTransportation: DS.attr('string'),
Accommodation: DS.attr('string'),
AcNumberNights: DS.attr('number'),
AcPreferHotel: DS.attr('string'),
AcPreferHotelUrl: DS.attr('string'),
Flight: DS.attr('string'),
FlDeparture: DS.attr('isodate'),
FlDepartPrefer: DS.attr('string'),
FlDepartPreferUrl: DS.attr('string'),
FlReturn: DS.attr('isodate'),
FlRetPrefer: DS.attr('string'),
FlRetPreferUrl: DS.attr('string'),
Notes: DS.attr('string'),
Files: DS.attr('string'),
Status: DS.attr('string')
});


controller:



App.EventsController = Ember.ArrayController.extend({});

and route:



App.Router.map(function () {
this.resource('sessions', function () {
this.route('logout');
this.route('login');
});

this.resource('help');

this.resource('events', function () {
this.route('list'),
this.route('new'),
this.route("event", { path: ":event_id" });
});
});

App.EventsNewRoute = Ember.Route.extend({
model: function (params) {
return this.store.createRecord('event', params);
}
});

App.EventsListRoute = Ember.Route.extend({
controllerName: 'events',
model: function () {
return this.store.find("event");
}
});




Aucun commentaire:

Enregistrer un commentaire