Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Ember Data and JSON API

1,609 views

Published on

Presentation given at the Belgium Ember.js meetup on the 20th of August 2014 (http://www.meetup.com/Ember-js-Belgium/events/198180452/).

The topics covered are:
- overview of Ember Data
- JSON API initiative (jsonapi.org)

Published in: Software
  • Be the first to comment

  • Be the first to like this

Ember Data and JSON API

  1. 1. Ember Data and JSON API @YoranBrondsema August 20th 2014
  2. 2. What is Ember Data?
  3. 3. The "M" in MVC Framework for managing your models and relationships
  4. 4. Separate project Different repository Can use Ember.js without Ember Data
  5. 5. Four main components Models Store Adapter Serializer
  6. 6. Specifying a model App.Post = DS.Model.extend({ /* Attributes */ title: DS.attr('string'), body: DS.attr('string'), nrViews: DS.attr('number'), createdAt: DS.attr('date'), isPublished: DS.attr('boolean'), /* Relationships */ author: DS.belongsTo('user'), comments: DS.hasMany('comment'), /* Properties */ hasComments: function() { return this.get('comments.length') > 0; }.property('comments.length') });
  7. 7. The store Contains all instances of models Is a singleton
  8. 8. Create and destroy instances store.createRecord store.deleteRecord
  9. 9. Query records store.find('post', 1) store.find('post') store.find('post', { isPublished: true })
  10. 10. The adapter Mediates between store and persistence layer
  11. 11. Write your own FixtureAdapter RESTAdapter LocalStorageAdapter?
  12. 12. Example RESTAdapter
  13. 13. Store find('post') ↓ RESTAdapter findAll('post') ↓ GET /posts
  14. 14. Store find('post', 1) ↓ RESTAdapter find('post', 1) ↓ GET /posts/1
  15. 15. Store find('post', { isPublished: true }) ↓ RESTAdapter findQuery('post', { isPublished: true }) ↓ GET /posts?is_published=true
  16. 16. Store createRecord('post') ↓ RESTAdapter createRecord('post') ↓ POST /posts
  17. 17. The serializer Serializes and normalizes data in a form expected by Ember Data Used by adapter When sending to server serialize When receiving from server normalize
  18. 18. Legacy API? JSON structure: custom serializers URLs: custom adapters
  19. 19. JSON API Specification to standardize representation of resources in JSON Driven by Yehuda Katz and Steve Klabnik jsonapi.org
  20. 20. Various implementations Ember Data RESTAdapter/RESTSerializer Rails ActiveModel::Serializers Python SQLAlchemy-JSONAPI
  21. 21. Status of Ember Data Right now v1.0.0-beta.9 Production release date not yet known Ember Data is still under active development and is currently beta quality. That being said, the API has largely stabilized and many companies are using it in production.
  22. 22. Thank you

×