active_model_serializers icon indicating copy to clipboard operation
active_model_serializers copied to clipboard

Normalizr adapter

Open adamcrown opened this issue 8 years ago • 4 comments

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'
      }
    }
  }
}

adamcrown avatar Jun 15 '16 05:06 adamcrown

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.

NullVoxPopuli avatar Jun 15 '16 07:06 NullVoxPopuli

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.

adamcrown avatar Jun 15 '16 08:06 adamcrown

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.

adamcrown avatar Jun 17 '16 15:06 adamcrown

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!

oyeanuj avatar Sep 04 '17 04:09 oyeanuj