An alternative solution could be to leverage ETags. Since there's a concept of equality between different role entities, you could return a
weak ETag when returning a role. The ETag's value would be calculated based on whatever determines equality, so two roles that'd be considered equal would have the same ETag. I suggest it should be weak since the response for two different roles would still be different.
Example: Let's say that two roles are considered equal if the have the same access level.
1. Retrieve role1.
Request:
GET /role/1
Response:
200 OK
ETag: W/"abc"
{
"id" : 1,
"name" : "Arthur",
"accessLevel" : 5
}
2. Check if role1 and role2 are equal.
Request:
GET /role/2
If-None-Match: W/"abc"
Response:
304 Not Modified
ETag: W/"abc"
(Ok, they're equal since the response was 304 Not Modified.)
3. Check if role2 and role3 are equal (and transitively role1 and role3).
Request:
GET /role/3
If-None-Match: W/"abc"
Response:
200 OK
ETag: W/"def"
{
"id" : 3,
"name" : "Ford",
"accessLevel" : 10
}
(Ok, role1 and role2 are not equal to role3 since the response was 200 OK.)
Requests could be done using HEAD instead to avoid retrieving the body.
Of course, this solution would however not allow you to do comparisons between several roles in a single request but it would save you from creating multiple new endpoints while allowing your service to save some bandwidth by using ETags.
Best,
Michael