So I heard you are working with custom APIs that are not either JSONAPI or REST but rather something in between, a hybrid. Then this addon is for you! It enables extracting metadata for all the Ember Data normalize*Response hooks.
ember install ember-json-serializer-meta
Works with Ember 1.13+
┌─ extractMetaFindAllResponse() ─────┐
├─ extractMetaFindHasManyResponse() ─┼─ extractMetaArrayResponse() ─────────────────────────────────┐
├─ extractMetaFindManyResponse() ────┤ │
├─ extractMetaQueryResponse() ───────┘ │
│ │
├─ extractMetaFindRecordResponse() ─────────────────────────────────┐ │
normalizeResponse() - normalizeMetaResponse() ─┼─ extractMetaFindBelongsToResponse() ──────────────────────────────┤ │
├─ extractMetaQueryRecordResponse() ────────────────────────────────┤ │
│ │ │
├─ extractMetaCreateRecordResponse() ─┐ │ │
├─ extractMetaDeleteRecordResponse() ─┼─ extractMetaSaveResponse() ─┴─ extractMetaSingleResponse() ─┴─ extractMetaResponse()
└─ extractMetaUpdateRecordResponse() ─┘
{
status: {
errorCode: 0
},
records: [{
id: 1,
name: 'Tomster'
}],
pagination: {
}
}
By default such payload is not supported by the JSONSerializer, it is impossible to extract metadata with default extractMeta
hook.
Here comes in the addon which adds another serializer hook for extracting meta for your custom API responses with JSONSerializer.
import extractMetaResponseMixin from 'ember-json-serializer-meta';
export default DS.JSONSerializer.extend(extractMetaResponseMixin, {
extractMetaResponse(store, typeClass, payload/*, id, requestType*/) {
if (payload && payload.pagination) {
return payload.pagination;
}
}
});
Default implementation of extractMetaResponse will lookup meta
property.
{
...
meta: {
my: 'meta'
}
...
}
This project follows Gitflow Workflow.
git clone
this repositoryyarn install
ember serve
- Visit your app at http://localhost:4200.
yarn test
(Runsember try:each
to test your addon against multiple Ember versions)ember test
ember test --server
ember build
For more information on using ember-cli, visit https://ember-cli.com/.