Class DS.RESTSerializer
Extends: | DS.JSONSerializer |
---|---|
Defined in: | addon/serializers/rest.js:21 |
Module: | ember-data |
Normally, applications will use the RESTSerializer
by implementing the normalize
method.
This allows you to do whatever kind of munging you need, and is especially useful if your server is inconsistent and you need to do munging differently for many different kinds of responses.
See the normalize
documentation for more information.
Across the Board Normalization
There are also a number of hooks that you might find useful to define across-the-board rules for your payload. These rules will be useful if your server is consistent, or if you're building an adapter for an infrastructure service, like Firebase, and want to encode service conventions.
For example, if all of your keys are underscored and all-caps, but otherwise consistent with the names you use in your models, you can implement across-the-board rules for how to convert an attribute name in your model to a key in your JSON.
app/serializers/application.js
import DS from 'ember-data'; import { underscore } from '@ember/string'; export default DS.RESTSerializer.extend({ keyForAttribute(attr, method) { return underscore(attr).toUpperCase(); } });
You can also implement keyForRelationship
, which takes the name of the relationship as the first parameter, the kind of relationship (hasMany
or belongsTo
) as the second parameter, and the method (serialize
or deserialize
) as the third parameter.
Methods
- extractAttributes
- extractErrors
- extractId
- extractMeta
- extractPolymorphicRelationship
- extractRelationship
- extractRelationships
- keyForAttribute
- keyForLink
- keyForPolymorphicType
- keyForRelationship
- modelNameFromPayloadKey
- modelNameFromPayloadType
- normalize
- normalize
- normalizeArrayResponse
- normalizeCreateRecordResponse
- normalizeDeleteRecordResponse
- normalizeFindAllResponse
- normalizeFindBelongsToResponse
- normalizeFindHasManyResponse
- normalizeFindManyResponse
- normalizeFindRecordResponse
- normalizeQueryRecordResponse
- normalizeQueryResponse
- normalizeResponse
- normalizeSaveResponse
- normalizeSingleResponse
- normalizeUpdateRecordResponse
- payloadKeyFromModelName
- payloadTypeFromModelName
- pushPayload
- serialize
- serialize
- serializeAttribute
- serializeBelongsTo
- serializeHasMany
- serializeId
- serializeIntoHash
- serializePolymorphicType
- shouldSerializeHasMany
Properties
Events
No documented items
© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember-data/2.18/classes/DS.RESTSerializer