# Does JSONAPI love singular resources?

**URL:** https://discuss.jsonapi.org/t/does-jsonapi-love-singular-resources/125
**Category:** Uncategorized
**Created:** [September 16, 2015, 3:59pm UTC](https://discuss.jsonapi.org/t/does-jsonapi-love-singular-resources/125 "2015-09-16T15:59:59Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![iamvery](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/iamvery/32/72_2.png) [@iamvery](https://discuss.jsonapi.org/u/iamvery)
#### Post date: [September 16, 2015, 3:59pm UTC](https://discuss.jsonapi.org/t/does-jsonapi-love-singular-resources/125/1 "2015-09-16T15:59:59Z")

</div>

What is jsonapi’s stance on singular resources? e.g. `/profile` which implies the profile for the authenticated user. I’m specifically interested in the payload for non-GET requests requiring an `id` attribute even though it may not be used for lookup.

---

<div class="post-metadata">

### Author: ![ethanresnick](https://avatars.discourse-cdn.com/v4/letter/e/45deac/32.png) [@ethanresnick](https://discuss.jsonapi.org/u/ethanresnick)
#### Post date: [September 16, 2015, 10:32pm UTC](https://discuss.jsonapi.org/t/does-jsonapi-love-singular-resources/125/2 "2015-09-16T22:32:40Z")

</div>

JSON API talks in terms of collections (which are the general case) but, at the end of the day, singular resources are totally allowed and are often necessary.

For consistency, JSON API still requires that they have an `id` (we don’t want clients to need custom parsing logic for these cases), but you can put any sensible value you want there. In your case, the id of the corresponding user might make sense (whether that be an email, username, or db index).

So for a hypothetical user with unique id `"bob"`, you’d have:

```auto
GET /profile

{
  "data": {
    "type": "profiles",
    "id": "bob",
    "attributes": { /* profile data here */ }
  }
}

```

and then

```auto
PATCH /profile

{
  "data": {
    "type": "profiles",
    "id": "bob",
    "attributes": { /* profile data here */ }
  }
}

```

Basically, `/profile` just functions like an alias (on both GET and PATCH) for `/profiles/bob`, and that’s fine. If you wanted to make this connection clearer, you could use `/profiles/active-user` as the URI, instead of `/profile`, but JSON API doesn’t require that you do so.

Finally, if you want to make bob’s profile available at _both_ `/profile` (or `/profiles/active-user`) when bob is signed in, and at `/profiles/bob` (e.g. for administrators), you could put a different `"self"` link at the top level and at the resource object level, like so:

```auto
GET /profile

{
  "links": {
    "self": "http://example.com/profile" // must be uri used to make the request.
  }
  "data": {
    "type": "profiles",
    "id": "bob",
    "attributes": { /* profile data here */ },
    "links": {
      "self": "http://example.com/profiles/bob" // canonical URI for this particular profile
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![iamvery](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/iamvery/32/72_2.png) [@iamvery](https://discuss.jsonapi.org/u/iamvery)
#### Post date: [September 19, 2015, 6:37pm UTC](https://discuss.jsonapi.org/t/does-jsonapi-love-singular-resources/125/3 "2015-09-19T18:37:56Z")

</div>

Thanks for the reply! Makes sense 😄

---

<div class="post-metadata">

### Author: ![toobulkeh](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/toobulkeh/32/171_2.png) [@toobulkeh](https://discuss.jsonapi.org/u/toobulkeh)
#### Post date: [December 22, 2015, 3:01am UTC](https://discuss.jsonapi.org/t/does-jsonapi-love-singular-resources/125/4 "2015-12-22T03:01:33Z")

</div>

What’s the thought process behind your `active-user` comments?  
Is there a reference that it’s from, or was it just a made up example?

---

<div class="post-metadata">

### Author: ![ethanresnick](https://avatars.discourse-cdn.com/v4/letter/e/45deac/32.png) [@ethanresnick](https://discuss.jsonapi.org/u/ethanresnick)
#### Post date: [December 23, 2015, 11:51pm UTC](https://discuss.jsonapi.org/t/does-jsonapi-love-singular-resources/125/5 "2015-12-23T23:51:43Z")

</div>

> [@toobulkeh](#):
>
> What’s the thought process behind your `active-user` comments?

There’s no specific recommendation in the spec for handling the page that shows the active user’s profile, if that’s what your asking. And the spec doesn’t constrain your URIs at all (except for some query parameter meanings).

My suggestion of `/profiles/active-user` for the URI instead of `/profile` was just to more clearly suggest to humans that the URI is picking out one resource from a typed collection (i.e. the active user from the set of profiles) in the same way `/people/1` is the spec’s suggested/conventional URI for requesting the resource `{type: people, id: 1}`.

---

<div class="post-metadata">

### Author: ![toobulkeh](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/toobulkeh/32/171_2.png) [@toobulkeh](https://discuss.jsonapi.org/u/toobulkeh)
#### Post date: [December 24, 2015, 12:59am UTC](https://discuss.jsonapi.org/t/does-jsonapi-love-singular-resources/125/6 "2015-12-24T00:59:12Z")

</div>

Yup, just asking for clarification on your thought process to that. I wasn’t quite able to understand with the original post that `active-user` was just the string form of an ID in your example. I understand it now, thanks!

---

<div class="post-metadata">

### Author: ![ethanresnick](https://avatars.discourse-cdn.com/v4/letter/e/45deac/32.png) [@ethanresnick](https://discuss.jsonapi.org/u/ethanresnick)
#### Post date: [December 24, 2015, 1:22am UTC](https://discuss.jsonapi.org/t/does-jsonapi-love-singular-resources/125/7 "2015-12-24T01:22:35Z")

</div>

Sure. And, just to clarify, `"active-user"` probably wouldn’t be the `"id"` of the JSON:API resource object returned at that URI; that `"id"` might be “bob” or similar, as in the example response.

My point was just meant to be that `/profiles/active-user` is a nice form because of its parallelism with `/profiles/1`. Again, not a perfect analogy, since `"1"` there is probably the literal value of an `"id"` key, whereas `"active-user"` isn’t, but it’s clearer imo than `/profile`.

---

<div class="post-metadata">

### Author: ![untidyhair](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/untidyhair/32/325_2.png) [@untidyhair](https://discuss.jsonapi.org/u/untidyhair)
#### Post date: [September 14, 2016, 9:28pm UTC](https://discuss.jsonapi.org/t/does-jsonapi-love-singular-resources/125/8 "2016-09-14T21:28:28Z")

</div>

> [@ethanresnick](#):
>
> “type”: “profiles”

Related question…  
Should the type still be plural? or does singular make sense, too?  
Thanks!

---

<div class="post-metadata">

### Author: ![iamvery](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/iamvery/32/72_2.png) [@iamvery](https://discuss.jsonapi.org/u/iamvery)
#### Post date: [September 14, 2016, 10:43pm UTC](https://discuss.jsonapi.org/t/does-jsonapi-love-singular-resources/125/9 "2016-09-14T22:43:03Z")

</div>

The plurality of the type does not reflect the plurality oft he resource. According to the spec, it doesn’t matter if the type is plural or singular so long as it’s consistent. [http://jsonapi.org/format/#document-resource-object-identification](http://jsonapi.org/format/#document-resource-object-identification)

---

<div class="post-metadata">

### Author: ![untidyhair](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/untidyhair/32/325_2.png) [@untidyhair](https://discuss.jsonapi.org/u/untidyhair)
#### Post date: [September 15, 2016, 8:25pm UTC](https://discuss.jsonapi.org/t/does-jsonapi-love-singular-resources/125/10 "2016-09-15T20:25:39Z")

</div>

Thanks for the clarification.
