Active_model_serializers: Normalizr adapter

Created on 15 Jun 2016  路  4Comments  路  Source: rails-api/active_model_serializers

React and Redux or Flux are becoming very popular. I'm working on a couple projects now that have Recat+Redux frontends. Certain JSON schemas are more easily integrated into Redux than others. Normalizr is a popular project for handling converting JSON schemas to a Redux/Flux friendly format. However, it seems like it would be better to just output a Normalizr-like schema directly. The JsonApi adapter is similar but not the same.

I'm mostly opening this issue to gauge interest from the community. If you'd be interested in a Normalizr adapter, please let me know. I've started work on an adapter already. If there is interest I'll put a little extra polish into it and release it as a gem or as a PR to this project.

Here's an example of JSON in Normalizr format so you can see what I'm aiming for:

{
  result: [1, 2],
  entities: {
    articles: {
      1: {
        id: 1,
        title: 'Some Article',
        author: 1
      },
      2: {
        id: 2,
        title: 'Other Article',
        author: 1
      }
    },
    users: {
      1: {
        id: 1,
        name: 'Dan'
      }
    }
  }
}

Most helpful comment

So here is what I have so far for anybody who's interested.

~https://github.com/worshipresourcemedia/active_model_normalizr~
https://github.com/codenoble/active_model_normalizr

The code is a bit messy and needs some refactoring, which I will hopefully be able to do soon but it seems to be working so far.

All 4 comments

I like the idea of using gems for additional adapters. :-)

When releasing, be sure to mention tested versions of AMS. I think there are plans to give all adapters the same functionality as JSON API. See: @bf4. So, the interface for making adapters may change before the 1.0 release.

Thanks. Right now I'm definitely just targeting 0.10.0 since I need to have this functionality soon. But I'll try to keep it up to date with new versions.

So here is what I have so far for anybody who's interested.

~https://github.com/worshipresourcemedia/active_model_normalizr~
https://github.com/codenoble/active_model_normalizr

The code is a bit messy and needs some refactoring, which I will hopefully be able to do soon but it seems to be working so far.

For anyone else who stumbles on this issue, the correct link now is: https://github.com/codenoble/active_model_normalizr

Thank you for throwing out the idea @adamcrown!

Was this page helpful?
0 / 5 - 0 ratings