How to create a custom model out of a JSON object fetched over REST?


#1

Sorry for the ignorance. Absolute noob to client side frameworks

Currently I’m trying to expose the data rendered by http://ghipak-api.herokuapp.com/v1/people/52aff3f0259e572ed6971ff7.

As you can see, the response is as below.

{ “id”: “52aff3f0259e572ed6971ff7”, “name”: “Syed Abbas”, “company”: “Room77”, “job_title”: “Manager Production”, “photo_url”: “http://m.c.lnkd.licdn.com/media/p/3/000/042/093/18f7c13.jpg”, “badges”: [ { “badge_id”: “52b292885d7918e9c10001e1”, “name”: “The Lion King”, “photo_url”: “http://example.com/badge_photo.jpg” } ], “reviews”: [ { “review_id”: “52b168e7cf4f83327f000173”, “feedback”: [ { “content”: “Magnificint comments.” } ] } ] }

If I try to use the REST adapter as shown in http://emberjs.com/guides/models/connecting-to-an-http-server/ It expects the model name as a key for the entry as well.

Any idea how I can accomplish making the ajax call for a key? basically, if I go to a url like “myhost.com/people/saaff3f0259e572ed6971ff7”, I should be able to fetch the post for that person. I want to completely do away with the whole data modeling(although I might adopt it if its fairly simple and felxible).

Any advice on this is really appreciated.

Thanks


#2

Check out the transition docs pertaining to serializers. They will allow you to define how ember should read the data coming from your server.


#3

Thanks so much for linking to this document. It also had some other amazingly useful information that I’ve been searching for the whole day, like the naming conventions for setting up custom adapters on a per-model basis. I’m busy building an app that will be backed by Rails, but it will also mash in information from a third-party service. Custom adapters & serializers is exactly what I’ve been looking for, but the proverbial penny only dropped now.

Been back up and down the ember guides and couldn’t find any references, so I’ll need to pick that up with the documentation folks.