Marcel Overdijk
Marcel Overdijk

Reputation: 11467

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?

Upvotes: 3

Views: 2027

Answers (2)

Cacho Casta&#241;a
Cacho Casta&#241;a

Reputation: 21

You migth want to check this article how-to-expose-the-resourceid-with-spring-data-rest

 @Configuration
public class MyCoolConfiguration extends RepositoryRestMvcConfiguration {

    @Override
    protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
        config.exposeIdsFor(FooEntity.class);
    }
}

Upvotes: 1

Jonathan W
Jonathan W

Reputation: 3799

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.

Upvotes: 4

Related Questions