How ember-cli handles fixtures

Written by Michael Lee on July 21, 2015

I’ve been really digging how ember-cli structures an ember.js project. One of the things I ran across yesterday was how ember-cli handles fixtures. Instead of the traditional way of setting up fixtures, ember-cli sets up what they call a http-mock. What this does is first install an express server and then sets up an API located at baseurl:4200/api/.

This is useful since your application will eventually be hooked up to an API, it allows you to setup your routes to perform HTTP requests via the API. I’m assuming the ember.js team is also pushing for this, as the documentation on fixtures has been absent from their documentation since version 1.12.0 and up.

To generate a http-mock, you can execute this command using the ember command-line tool, ember generate http-mock route-name. From there you can setup fixture data using the files located at server/mocks/route-name.js. The routes could also be accessed via the browser but navigating to http://localhost:4200/api/route-name.

Documentation on http-mock could be found on the ember-cli page but I found the documentation to be sparse. Doing a Google search yielded better explanation about this feature.

Thanks for taking the time to read this article. I'd love to stay in touch and share more tips on programming and design, side projects and working remotely. Sign up and I'll send you my articles straight to your email.

:wave: Hey hey, I'm Michael Lee! I really appreciate you taking the time to read this article.

Be sure to check out my other articles.