Thanks for all your help on this @dknutsen. Here is mirage/config.js
export default function() {
this.namespace = "/api";
this.get('/words', function({ words }, { queryParams }) {
let { word } = queryParams;
if (!word) {
return words.all();
} else {
word = word.toLowerCase();
return words.all().filter(w => w.toLowerCase().includes(word));
}
});
this.get('/words/:word', function ({ words }, request) {
return words.findBy({ word: request.params.word });
});
}
The router.js
.
import EmberRouter from "@ember/routing/router";
import config from "./config/environment";
const Router = EmberRouter.extend({
location: config.locationType,
rootURL: config.rootURL
});
Router.map(function() {
this.route("home", { path: "/" });
this.route("words", { path: "/words/:word_id" });
});
export default Router;
And app/pods/words/route.js
.
import EmberRouter from "@ember/routing/router";
import config from "./config/environment";
const Router = EmberRouter.extend({
location: config.locationType,
rootURL: config.rootURL
});
Router.map(function() {
this.route("home", { path: "/" });
this.route("words", { path: "/words/:word_id" });
});
export default Router;
Also have this in mirage/scenarios/default.js
.
export default function(server) {
server.loadFixtures("words");
server.logging = true
}
With all this in place, now when you go to http://localhost:4200/words/bean
you get the following error:
WARNING: You requested a record of type 'word' with id 'bean' but the adapter returned a payload with primary data having an id of '5'. Use 'store.findRecord()' when the requested id is the same as the one returned by the adapter. In other cases use 'store.queryRecord()' instead https://emberjs.com/api/data/classes/DS.Store.html#method_queryRecord
Here is the app/adapters/application.js
.
import DS from "ember-data";
export default DS.JSONAPIAdapter.extend({
namespace: "api"
});
Thoughts?