Create resource and assign relationship

Hello,

I want to create users resource ( POST /users ) and assign currency relationship. Which one is correct according the specification. I was thinking about first one since it makes sense to isolate relationship from attributes, but still I’m not sure.

{
  "data": {
    "type": "users",
    "attributes": {
      "username": "username"
    },
    "relationships": {
      "currency": {
        "data": { "type": "currencies", "id": "1" }
      }
    }
  }
}

or

{
  "data": {
    "type": "users",
    "attributes": {
      "username": "username",
      "currency_id": "1"
    }
  }
}

Thanks

What made you doubt?

The first example you gave is according to the spec. It states (JSON:API — Latest Specification (v1.1)):

Although has-one foreign keys (e.g. author_id ) are often stored internally alongside other information to be represented in a resource object, these keys SHOULD NOT appear as attributes.

There is also an example (JSON:API — Latest Specification (v1.1)) of a create which looks similar to yours where a relationship is passed to assign alongside with the creation of the main resource.