ember data and json api
DESCRIPTION
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)TRANSCRIPT
![Page 2: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/2.jpg)
What is Ember Data?
![Page 3: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/3.jpg)
The "M" in MVC
Framework for managing your models and relationships
![Page 4: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/4.jpg)
Separate project
Different repository
Can use Ember.js without Ember Data
![Page 5: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/5.jpg)
Four main componentsModels
Store
Adapter
Serializer
![Page 6: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/6.jpg)
Specifying a modelApp.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')});
![Page 7: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/7.jpg)
The store
Contains all instances of models
Is a singleton
![Page 8: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/8.jpg)
Create and destroy instances
store.createRecord
store.deleteRecord
![Page 9: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/9.jpg)
Query records
store.find('post', 1)
store.find('post')
store.find('post', { isPublished: true })
![Page 10: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/10.jpg)
The adapterMediates between store and persistence layer
![Page 11: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/11.jpg)
Write your own
FixtureAdapter
RESTAdapter
LocalStorageAdapter?
![Page 12: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/12.jpg)
Example RESTAdapter
![Page 13: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/13.jpg)
Store find('post')
↓
RESTAdapter findAll('post')
↓
GET /posts
![Page 14: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/14.jpg)
Store find('post', 1)
↓
RESTAdapter find('post', 1)
↓
GET /posts/1
![Page 15: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/15.jpg)
Store find('post', { isPublished: true })
↓
RESTAdapter findQuery('post', { isPublished: true })
↓
GET /posts?is_published=true
![Page 16: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/16.jpg)
Store createRecord('post')
↓
RESTAdapter createRecord('post')
↓
POST /posts
![Page 17: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/17.jpg)
The serializerSerializes and normalizes data in a form expected by Ember Data
Used by adapter
When sending to server serialize
When receiving from server normalize
![Page 18: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/18.jpg)
Legacy API?JSON structure: custom serializers
URLs: custom adapters
![Page 19: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/19.jpg)
JSON APISpecification to standardize representation of resources in JSON
Driven by Yehuda Katz and Steve Klabnik
jsonapi.org
![Page 20: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/20.jpg)
Various implementations
Ember Data RESTAdapter/RESTSerializer
Rails ActiveModel::Serializers
Python SQLAlchemy-JSONAPI
![Page 21: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/21.jpg)
Status of Ember DataRight 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 beingsaid, the API has largely stabilized and many companies are using it in production.
![Page 22: Ember Data and JSON API](https://reader034.vdocuments.us/reader034/viewer/2022051013/547ca9215906b561378b4589/html5/thumbnails/22.jpg)
Thank you