spring-projects / spring-hateoas-examples

Collection of examples on how (and why) to build hypermedia-driven apps with Spring HATEOAS
Apache License 2.0
384 stars 186 forks source link

Leverage Spring Data REST's link building utility #28

Open gregturn opened 5 years ago

gregturn commented 5 years ago

Current, we have to do stuff like this to mesh a custom controller with a Spring Data REST one.

private static Link applyBasePath(Link link, String basePath) {

    URI uri = link.toUri();

    URI newUri = null;
    try {
        newUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), //
                uri.getPort(), basePath + uri.getPath(), uri.getQuery(), uri.getFragment());
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    return new Link(newUri.toString(), link.getRel());
}

Take advantage of DATAREST-1423 to simplify the integration.