The following scenario does not follow RESTful standards and would be keen to know how best to structure my API to achieve the same goal.
For a given GET request against a resource, e.g. GET /api/person/1, if the principle contains a claim I would like to return additional properties.
E.g.
GET /api/person/1 (Without IsAdmin claim)
{
name: "Buck Rogers",
dateOfBirth: 2000-01-01T00:00:00.000
}
GET /api/person/1 (With IsAdmin claim)
{
name: "Buck Rogers",
dateOfBirth: 2000-01-01T00:00:00.000,
adminNote: "Something private"
}
So I'd conditionally be returning two different DTOs for the same resource request, which isn't allowed.
How can I achieve this in a RESTful way?
Update:
It was suggested I could define the adminNote property and NULL it based on the condition. How would I deal with the case where there might be multiple conditionals that determine which properties are included? E.g.
GET /api/person/1 (With IsModerator claim)
{
name: "Buck Rogers",
dateOfBirth: 2000-01-01T00:00:00.000,
moderatorNote: "Something else private"
}
I would be keen to avoid adding extra properties that will only ever not be null in one particular case.