springspring-hateoashypermedia

How to present resource id to client?


org.springframework.hateoas.ResourceSupport already contains a getId method.

In case my resource (or better domain object) contains an integer id which needs to be presented to the client I cannot add a simple id and add getId/setId (as ResourceSupport already has it).

Should I return something <myResourceObjectName>_id or is it better to just let the client interpret the id link/URL provided by ResourceSupport?


Solution

  • For the purposes of the client, the URL the resource was initially retrieved from (via a GET) is its id. No interpreting should occur and the client should treat the URL as an opaque string.