# Load raw data via API endpoint, get Ember to transform it into corresponding models

**URL:** <https://discuss.emberjs.com/t/load-raw-data-via-api-endpoint-get-ember-to-transform-it-into-corresponding-models/3547>\
**Category:** Uncategorized\
**Created:** [December 9, 2013, 4:07pm UTC](https://discuss.emberjs.com/t/load-raw-data-via-api-endpoint-get-ember-to-transform-it-into-corresponding-models/3547 "2013-12-09T16:07:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![commadelimited](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/commadelimited/32/3548_2.png) [@commadelimited](https://discuss.emberjs.com/u/commadelimited)\
**Post date:** [December 9, 2013, 4:07pm UTC](https://discuss.emberjs.com/t/load-raw-data-via-api-endpoint-get-ember-to-transform-it-into-corresponding-models/3547/1 "2013-12-09T16:07:55Z")

</div>

I’d like Ember (and Data) to request models from an API endpoint, but transform the raw data into models so that Ember can use it transparently.

### The problem

We load in data via a number of API endpoints when the page loads. We also push data to the page via Pusher. In an effort to consolidate the transforming of raw data into a single location we’ve decided to put that logic on the client. When we push new data to the page, we have a utility method that transforms that data into an **Interaction** record.

Now, we need to also transform the raw data that the server passes to the page via AJAX request. It needs to pass through the same utility method, but I’m not sure where to intercept the response from the API so that I can properly transform the data. Where should I be looking, and what methods are at my disposal?

The raw data will be different based on the type of information it is, but here’s a single example:

```auto
{
    "created_at": "Wed May 01 18:32:43 +0000 2013",
    "id": 329664697345384448,
    "id_str": "329664697345384448",
    "text": "@steveWINton true dat",
    "user": {
        "created_at": "Thu Feb 14 13:07:51 +0000 2008",
        "id": 13470142,
        "id_str": "13470142",
        "name": "uo\u0287u\u0131\u028d\u01dd\u028c\u01dd\u0287s",
        "screen_name": "NOTsteveWINton"
    }
}

```

And it needs to be converted into the following format:

```auto
Social.Interaction = DS.Model.extend({
    native_id: DS.attr("string"),
    screen_name: DS.attr("string"),
    name: DS.attr("string"),
    text: DS.attr("string")
});

```

cc-ing @toranb in case this might directly involve routing through the Django Rest Adapter.

---

<div class="post-metadata">

**Author:** ![commadelimited](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/commadelimited/32/3548_2.png) [@commadelimited](https://discuss.emberjs.com/u/commadelimited)\
**Post date:** [December 9, 2013, 4:31pm UTC](https://discuss.emberjs.com/t/load-raw-data-via-api-endpoint-get-ember-to-transform-it-into-corresponding-models/3547/2 "2013-12-09T16:31:12Z")

</div>

I found another response that seemed to indicate that Ember had a preprocessData method but when I tried to implement that it did nothing:

> [@Loading partial models then filling them with Ember-data](http://discuss.emberjs.com/t/loading-partial-models-then-filling-them-with-ember-data/819/3):
>
> I’ve been trying to figure this out for a while and think I finally stumbled on something that works pretty well for me, YMMV. I just overrode the preprocessData function on my App.Store to check if the data I’m supplying is a full item or partial, based on the attribute basicInfo, then checks to see if the item is already in the Store, and returns accordningly Here’s what my App.Store looks like now App.Store = DS.Store.extend( revision: 12 preprocessData: (type, data) -\> if data.ba…

---

<div class="post-metadata">

**Author:** ![toranb](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/toranb/32/16579_2.png) [@toranb](https://discuss.emberjs.com/u/toranb)\
**Post date:** [December 9, 2013, 5:42pm UTC](https://discuss.emberjs.com/t/load-raw-data-via-api-endpoint-get-ember-to-transform-it-into-corresponding-models/3547/3 "2013-12-09T17:42:29Z")

</div>

Just to clarify -you want to override the generic “side loading” ember-data does when your $.ajax request is resolved successfully? (during normal find / find all like logic) ? -what about create /update /delete?

---

<div class="post-metadata">

**Author:** ![commadelimited](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/commadelimited/32/3548_2.png) [@commadelimited](https://discuss.emberjs.com/u/commadelimited)\
**Post date:** [December 9, 2013, 7:20pm UTC](https://discuss.emberjs.com/t/load-raw-data-via-api-endpoint-get-ember-to-transform-it-into-corresponding-models/3547/4 "2013-12-09T19:20:09Z")

</div>

When the page loads, we’re passing in a list of interaction IDs. Ember will then sideload the full data by hitting the interactions API endpoint. That part will not change from the way it currently works.

What we want is to be able to pass raw data to the page from the interactions endpoint rather than the “final” version of the model.
