Skip to content

Service Addon

Bill Heaton edited this page May 10, 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 true 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.

In-repo addon

An alternative to a stand-alone addon is to use an "In-Repo Addon"; example of generating an in-repo addon below…

ember install ember-jsonapi-resources
ember generate in-repo-addon hotels-service
ember generate jsonapi-resource hotel name:string reservation-date:date duration:number created-at:date updated-at:date --in-repo-addon hotels-service
Clone this wiki locally