Adapters and Serializers

  1. Overview of Use
  2. Overview of Customization
  3. Using Adapters
  4. Customizing Adapters
  5. RESTAdapter
  6. JSONAPIAdapter
  7. Using Serializers
  8. Customizing Serializers
  9. RESTSerializer
  10. JSONAPISerializer

A 10(?)-part series

Adapters and Serializers

  1. Overview of Use
  2. Overview of Customization
  3. Using Adapters
  4. Customizing Adapters
  5. RESTAdapter
  6. JSONAPIAdapter
  7. Using Serializers
  8. Customizing Serializers
  9. RESTSerializer
  10. JSONAPISerializer

A 10(?)-part series

Adapters:

Serializers:

URL

Data

Image Source: http://emberigniter.com/fit-any-backend-into-ember-custom-adapters-serializers/

DS.ActiveModelSerializer

DS.ActiveModelAdapter

Adapters and Serializers

  1. Overview of Use
  2. Overview of Customization
  3. Using Adapters
  4. Customizing Adapters
  5. RESTAdapter
  6. JSONAPIAdapter
  7. Using Serializers
  8. Customizing Serializers
  9. RESTSerializer
  10. JSONAPISerializer

A 10(?)-part series

Adapters and Serializers

  1. Overview of Use
  2. Overview of Customization
  3. Using Adapters
  4. Customizing Adapters
  5. RESTAdapter
  6. JSONAPIAdapter
  7. Using Serializers
  8. Customizing Serializers
  9. RESTSerializer
  10. JSONAPISerializer

A 10(?)-part series

Starting from "Scratch": Serializers

import DS from 'ember-data';

export default DS.Serializer.extend({
    serialize(snapshot, options){
        // code here
    },

    normalizeResponse(store, primaryModelClass, payload, id, requestType){
        // code here
    },

    normalize(modelClass, resourceHash){
        // optional
        // code here
    }
})

Starting from "Scratch": Adapters

import DS from 'ember-data';

export default DS.Adapter.extend({
    findRecord(store, type, id, snapshot){},
    createRecord(store, type, snapshot){},
    updateRecord(store, type, snapshot){},
    deleteRecord(store, type, snapshot){},
    findAll(store, type, sinceToken){},
    query(store, type, query){},

    //optional, to increase speed
    findMany(store, type, ids, snapshots){}
})

JSONSerializer

 

  • attrs
  • primaryKey 
  • normalizeX
  • serializeX 
  • keyForX
  • extractX
  • modelNameFrom-

        PayloadKey

Each method is a leverage point

that strategically interacts with other methods

JSONSerializer vs Others

Method Added in
pushPayload REST && JSONAPI
payloadKeyFromModelName REST && JSONAPI
keyForPolymorphicType REST

Mostly the same (except)

RESTAdapter

  • namespace
  • host 
  • headers
  • buildUrl 
  • urlForX
  • findX
  • (create/delete/update)Record
  • generateIdForRecord
  • groupRecordsForFindMany
  • handleResponse
  • is(Invalid/Success)
  • pathForType
  • query(X)
  • serialize
  • shouldReloadX
  • sortQueryParams

RESTAdapter vs JSONAPI

Exactly the same

Made with Slides.com