spring-projects / spring-projects/spring-data-rest
Simplify creating links against @BasePathAware controllers outside of SDR [DATAREST-1423]
@gregturn is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Greg Turnquist opened DATAREST-1423 and commented
In Spring HATEAOS Examples (https://github.com/spring-projects/spring-hateoas-examples/blob/master/spring-hateoas-and-spring-data-rest/src/main/java/org/springframework/hateoas/examples/OrderProcessor.java#L88-L101), to create a custom endpoint using @BasePathAwareController, it requires extra handling to insert the basePath into the whole URI, like this:
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());
}
Some form of utility, whether its a LinkBuilder or something else would make it easier for users to mesh custom controllers with SDR's controllers
Referenced from: commits https://github.com/spring-projects/spring-data-rest/commit/b527d323e0cec0ad8287da0410dfde32498d792e, https://github.com/spring-projects/spring-data-rest/commit/b1987411f3223aef446962c36935abb7057030f7
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.