# Is my usage of nested resources and relations approach are right?

**URL:** <https://discuss.jsonapi.org/t/is-my-usage-of-nested-resources-and-relations-approach-are-right/349>\
**Category:** Uncategorized\
**Created:** [February 18, 2016, 7:31am UTC](https://discuss.jsonapi.org/t/is-my-usage-of-nested-resources-and-relations-approach-are-right/349 "2016-02-18T07:31:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![deividas](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@deividas](https://discuss.jsonapi.org/u/deividas)\
**Post date:** [February 18, 2016, 7:31am UTC](https://discuss.jsonapi.org/t/is-my-usage-of-nested-resources-and-relations-approach-are-right/349/1 "2016-02-18T07:31:33Z")

</div>

Hello,

I’m implementing jsonapi spec in our API and i want make sure that i understand everything correctly.  
Here’s full nested resource url: /v1/countries/1/states/42

I will give response output by going through all resources. Maybe something should or can be improved here?

Endpoint: _/v1/countries_

```
{
  "data": [
    {
          "type": "country",
          "id": "4",
          "attributes": {
            "country": "American Samoa",
            "calling_code": {
              "0": 1684
            }
          }
        }
      ]
    }

```

Endpoint: _/v1/countries/4_

```
{
  "data": {
    "type": "country",
    "id": "4",
    "attributes": {
      "country": "American Samoa",
      "calling_code": {
        "0": 1684
      }
    },
    "relationships": {
      "states": {
        "data": [
          {
            "type": "state",
            "id": "164"
          }
        ]
      }
    }
  },
  "included": [
    {
      "type": "state",
      "id": "164",
      "attributes": {
        "state": "Eastern"
      }
    }
  ]
}

```

Endpoint: _/v1/countries/4/states_

```
{
  "data": [
    {
      "type": "state",
      "id": "164",
      "attributes": {
        "state": "Eastern"
      }
    },
    {
      "type": "state",
      "id": "165",
      "attributes": {
        "state": "Manu'a"
      }
    }
  ]
}

```

Endpoint: _/v1/countries/4/states/164_

```
{
  "data": {
    "type": "state",
    "id": "164",
    "attributes": {
      "state": "Eastern"
    },
    "relationships": {
      "cities": {
        "data": [
          {
            "type": "city",
            "id": "6414"
          },
          {
            "type": "city",
            "id": "6415"
          }
        ]
      }
    },
    "included": [
      {
        "type": "city",
        "id": "6414",
        "attributes": {
          "city": "Afono"
        }
      },
      {
        "type": "city",
        "id": "6415",
        "attributes": {
          "city": "Alao"
        }
      }
    ]
  }
}

```

Thanks!

---

<div class="post-metadata">

**Author:** ![brainwipe](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/brainwipe/32/209_2.png) [@brainwipe](https://discuss.jsonapi.org/u/brainwipe)\
**Post date:** [February 19, 2016, 9:36am UTC](https://discuss.jsonapi.org/t/is-my-usage-of-nested-resources-and-relations-approach-are-right/349/2 "2016-02-19T09:36:49Z")

</div>

It looks valid to me.

Will you be including any links? They are optional but for me those hypermedia references is the power of using JSON Api.

---

<div class="post-metadata">

**Author:** ![deividas](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@deividas](https://discuss.jsonapi.org/u/deividas)\
**Post date:** [February 22, 2016, 6:51am UTC](https://discuss.jsonapi.org/t/is-my-usage-of-nested-resources-and-relations-approach-are-right/349/3 "2016-02-22T06:51:41Z")

</div>

Thanks for taking a look!

Yes, i’m going to consider add these ( links ), thanks for your note.  
In this example they are missing because i wanted to make sure that everything else is good.

---

<div class="post-metadata">

**Author:** ![skaaptjop](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/skaaptjop/32/619_2.png) [@skaaptjop](https://discuss.jsonapi.org/u/skaaptjop)\
**Post date:** [May 21, 2019, 3:09pm UTC](https://discuss.jsonapi.org/t/is-my-usage-of-nested-resources-and-relations-approach-are-right/349/4 "2019-05-21T15:09:11Z")

</div>

> [@deividas](#):
>
> Endpoint: _/v1/countries_

Why would the returned data in the array not include the relationship objects? Why would you need to fetch them individually at `/v1/countries/4`?
