Skip to content

Service Addon

Bill Heaton edited this page Apr 12, 2016 · 5 revisions

Use the ember-jsonapi-resources addon to create a data "service" Addon for your Ember applications.

Problem

Many Ember apps use the same API and same endpoints. Each application could install an Ember CLI Addon as a data service module for a specific API endpoint (resource).

Solution

  1. Generate an Addon
  2. Uninstall Ember Data
  3. Install the ember-jsonapi-resources addon
  4. Generate a jsonapi-resource
  5. Generate a blueprint
  6. Update your package.json with description and version.

Below is a summary of the commands to setup a data service addon using ember-jsonapi-resources…

ember addon hotels-service
npm rm ember-data --save-dev
ember install ember-jsonapi-resources
ember g jsonapi-resource hotel name:string reservation_date:date duration:number created-at:date updated-at:date
ember generate jsonapi-blueprint hotels-service

Use npm link for local development using your data service.

In your package.json use a github URL to reference the dependency:

"dependencies": {
  "hotels-service": "git+ssh://git@github.com:organization/hotels-service.git#0.1.0"
}

If you do not wish to publish your NPM module, in your package.json file… set private to false and license to "UNLICENSED".

Discussion

There is no requirement to using services for each of your API endpoints. This is an advantage only when you have many apps or perhaps engines.

Clone this wiki locally