当我尝试向Dark Sky发出GET请求时,我知道为什么我会得到404? https://darksky.net/dev/docs
错误:
jquery.js:9600 GET https://api.darksky.net/forecast?key=secretString&latitude=42.361145&longitude=-71.057083&time=1525213510 404 (Not Found)
这是我的模特:
import DS from 'ember-data';
export default DS.Model.extend({
temperature: ('number'),
summary: DS.attr('string'),
icon: DS.attr('string')
});
这是我的路线(我也试图以字符串格式保留lat和long):
import Route from '@ember/routing/route';
export default Route.extend({
model () {
let currentTime = Math.round(new Date()/1000);
return this.store.query('weather', { key: "secret_string", latitude: 42.361145, longitude: -71.057083, time: currentTime} );
}
});
这是我的适配器:
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
host: "https://api.darksky.net",
pathForType() {
return 'forecast';
}
});
这是我的序列化器:
import DS from 'ember-data';
export default DS.RESTSerializer.extend({
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
payload = { weather: payload };
return this._super(store, primaryModelClass, payload, id, requestType);
}
});
答案 0 :(得分:2)
您的GET请求不符合Dark Sky文档中的格式,复制并粘贴在下方:
https://api.darksky.net/forecast/0123456789abcdef9876543210fedcba/42.3601,-71.0589
您的请求将密钥作为查询参数而非URL段。
您可以在适配器中指定主机或命名空间,以使密钥成为网址段:
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
host: "https://api.darksky.net/yoursecretkey",
});