# Nested dynamic segments using RestAdapter

**URL:** <https://discuss.emberjs.com/t/nested-dynamic-segments-using-restadapter/6524>\
**Category:** Ember Data\
**Created:** [October 19, 2014, 8:52pm UTC](https://discuss.emberjs.com/t/nested-dynamic-segments-using-restadapter/6524 "2014-10-19T20:52:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kgish](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/kgish/32/13333_2.png) [@kgish](https://discuss.emberjs.com/u/kgish)\
**Post date:** [October 19, 2014, 8:52pm UTC](https://discuss.emberjs.com/t/nested-dynamic-segments-using-restadapter/6524/1 "2014-10-19T20:52:12Z")

</div>

I’ve been struggling some time to get the following situation working:

```
GET /folders => list of folders (folder_id, folder_name, ...)
GET /folders/:folder_id/items => list of items (item_id, item_name, ...) belonging to given folder with folder_id
GET /folders/:folder_id/items/:item_id => details (details_subject...) of item with item_id belonging to given folder with folder_id

```

A folder can have one or more items, but an item has only one details which is a single record with a number of fields.

I have some influence over the API so can introduce side-loading links if needed.

I’d be very thankful if someone could point me out to the best way to tackle this.

---

<div class="post-metadata">

**Author:** ![chadhietala](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/chadhietala/32/14343_2.png) [@chadhietala](https://discuss.emberjs.com/u/chadhietala)\
**Post date:** [October 20, 2014, 5:39am UTC](https://discuss.emberjs.com/t/nested-dynamic-segments-using-restadapter/6524/2 "2014-10-20T05:39:36Z")

</div>

You have several options.

### Use `buildURL()`

In `buildURL` you have access to record as the third option. With that you can do the following:

```auto
buildURL: function (type, id, record) {
  return '/folders/' + id + '/items/' + record.get('item.id');
}

```

### Send Links Metadata

You can implement an `extractMeta` where you store off the href for this record. When you implement `buildURL` you can just pull the metadata off the type. This is handy if you’re talking to a HAL JSON backend.

### Synthetic Key

Instead of the backend issuing a single ID it can issue a sythentic id which is the combination of the 2 keys e.g. `"12-42"`.

Here some more resources

> [@Best Practices for Web Service Design with Ember Data](http://discuss.emberjs.com/t/best-practices-for-web-service-design-with-ember-data/5654):
>
> Hello, I am in the process of designing the web service backend that our Ember-Data app will consume, and I have a few questions on best practices here. I did not find a related post, but if I missed it, please let me know. Responses on many, all or just one of the below items are welcome! 1. Extensive Use of Database Views? At first, I assumed the models in Ember-Data should basically match 1-to-1 with the tables in our database, but increasingly I’m seeing that my frontend is more of a “su…

[http://codeofficer.com/blog/2013/10/03/ember-data-faking-a-composite-key.html](http://codeofficer.com/blog/2013/10/03/ember-data-faking-a-composite-key.html)

---

<div class="post-metadata">

**Author:** ![kgish](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/kgish/32/13333_2.png) [@kgish](https://discuss.emberjs.com/u/kgish)\
**Post date:** [October 20, 2014, 7:20am UTC](https://discuss.emberjs.com/t/nested-dynamic-segments-using-restadapter/6524/3 "2014-10-20T07:20:09Z")

</div>

I think that for my situation using `buildURL` would make the most sense. How can I distinguish within the RESTAdapter when to use this, e.g. that indeed this call is for building the items url?

---

<div class="post-metadata">

**Author:** ![chadhietala](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/chadhietala/32/14343_2.png) [@chadhietala](https://discuss.emberjs.com/u/chadhietala)\
**Post date:** [October 20, 2014, 2:42pm UTC](https://discuss.emberjs.com/t/nested-dynamic-segments-using-restadapter/6524/4 "2014-10-20T14:42:37Z")

</div>

You can can infer the request by doing:

```auto
record.get('dirtyType'); // created, updated, deleted

```
