Question

Are there disadvantages to allowing a RESTful API to accept a representation with an implicit link to another resource?

To illustrate this, take that I have two resources:

GET /people/:id
GET /houses/:id

A person has a unique identifier in addition to id, which is their email.

Are there disadvantages to allowing the following interaction?

POST /houses
{
    "_links": {
        "owner": {
            "email": "example@example.com"
        }
    },
    "street_number": 20
}

The server know that the email field is unique, and therefore can be used to identify the people resource. It will create an association to that person.

The reason to allow this would be to make it easier on the API client, where they don't have to first look up the URI of the resource.

In contrast, I would certainly allow this type of call:

POST /houses
{
    "_links": {
        "owner": {
            "href": "/people/3"
        }
    },
    "street_number": 20
}
Was it helpful?

Solution

The common sense should drive here. If in your business model the user has a unique email, there is no drawback for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top