I'm trying to get data from remote backend api. As I followed the docs, (http://ift.tt/29SEXvp), 'The JSONAPIAdapter is smart enough to determine the URLs it communicates with based on the name of the model.' So I generated the Route, the Model and the Adapter.
Here's the code of the Adapter:
//app/adapters/app.js
import Ember from 'ember';
import JSONAPIAdapter from 'ember-data/adapters/json-api';
import JSONAPISerializer from 'ember-data/serializers/json-api';
export default JSONAPIAdapter.extend({
ajax: Ember.inject.service(),
host: 'http://ift.tt/1nhHxYZ',
headers: {
'API_KEY': '72b56103e43843412a992a8d64bf96e9'
},
pathForType: function(type) {
return Ember.String.underscore(type);
},
serializer: JSONAPISerializer.extend({
primaryKey: 'id',
serializeId: function(id) {
return id.toString();
}
})
});
The code of the Model
//app/models/movie.js
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
// import { belongsTo, hasMany } from 'ember-data/relationships';
export default Model.extend({
poster_path: attr('string'),
adult: attr('boolean'),
overview: attr('string'),
release_date: attr('string'),
genre_ids: attr('array'),
original_title: attr('string'),
original_language: attr('string'),
title: attr('string'),
backdrop_path: attr('string'),
popularity: attr('number'),
vote_count: attr('number'),
video: attr('boolean'),
vote_average: attr('number')
});
The Router of the app:
//app/router.js
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: config.locationType
});
Router.map(function() {
this.route('movies', {
path: '/'
});
});
export default Router;
And the code of the Route:
//app/routes/movies.js
import Ember from 'ember';
import Movie from 'search-movies/models/movie';
export default Ember.Route.extend({
model() {
return this.store.findAll('movie');
}
});
But if I run the app, I get the error of 404:
Error while processing route: movies Ember Data Request GET /movies returned a 404
I guess, the store service can't get the models. But why? I've generated the Adapter. Do I need to import it somewhere? Or what? Why this structure doesn't work? Need help.
Aucun commentaire:
Enregistrer un commentaire