Adapters and Serializers
- Overview of Use
- Overview of Customization
- Using Adapters
- Customizing Adapters
- RESTAdapter
- JSONAPIAdapter
- Using Serializers
- Customizing Serializers
- RESTSerializer
- JSONAPISerializer
A 10(?)-part series
Adapters and Serializers
- Overview of Use
- Overview of Customization
- Using Adapters
- Customizing Adapters
- RESTAdapter
- JSONAPIAdapter
- Using Serializers
- Customizing Serializers
- RESTSerializer
- 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
- Overview of Use
- Overview of Customization
- Using Adapters
- Customizing Adapters
- RESTAdapter
- JSONAPIAdapter
- Using Serializers
- Customizing Serializers
- RESTSerializer
- JSONAPISerializer
A 10(?)-part series
Adapters and Serializers
- Overview of Use
- Overview of Customization
- Using Adapters
- Customizing Adapters
- RESTAdapter
- JSONAPIAdapter
- Using Serializers
- Customizing Serializers
- RESTSerializer
- 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
Adapters and Serializers
By Jeffrey Biles
Adapters and Serializers
- 2,428