normalize-json-api
v0.1.1
Published
Normalizes JSON API responses for Redux and Flux applications
Downloads
6
Maintainers
Readme
normalize-json-api
Normalizes JSON API responses according to a schema for Flux and Redux apps. More on JSON API. Thanks to paularmstrong and Dan Abramov for building normalizr where the original idea of this library came from :)
Installation
npm install --save normalize-json-api
The Problem
- You have a JSON API sideloaded objects ;
- You want to port your app to Flux or Redux;
- You noticed it's hard for Stores (or Reducers) to consume data from nested API responses.
normalize-json-api takes JSON API and
For example,
{
data: {
id: 1,
type: 'articles',
attributes: {
title: 'Shoes',
'is-favorite': false,
},
relationships: {
author: {
data: {
type: 'users',
id: 9,
},
},
},
},
included: [
{
type: 'users',
id: 9,
attributes: {
'first-name': 'Marie',
'last-name': 'Brizard',
twitter: 'mb',
},
},
],
}
can be normalized to
{
results: {
articles: [1],
users: [9],
},
entities: {
articles: {
1: {
id: 1,
type: 'articles',
title: 'Shoes',
isFavorite: false,
author: 9,
},
},
users: {
9: {
id: 9,
type: 'users',
firstName: 'Marie',
lastName: 'Brizard',
twitter: 'mb',
},
},
},
}
Features
TODO
Usage
TODO
Credits
normalize-json-api was inspired heavily by normalizr