How to build a templated link?
Asked Answered
D

2

6

I have a method with a request parameter and I'm trying to link to this method from another resource. I want the link to be something like this:

"rel":{
  "href":".../resources{?param}",
  "templated":true     
}

I tried the following without success:

//First attempt
resources.add(linkTo(methodOn(Controller.class).method(null)).withRel("rel")       
//Second attempt
resources.add(linkTo(methodOn(Controller.class).method("{parameter}")).withRel("rel")
//Third attempt
resources.add(entityLinks.linkToCollectionResource(LinkedResource.class).withRel("rel");
Disaccharide answered 23/3, 2015 at 19:33 Comment(0)
I
4

It does work now, you can check the following issue which has been resolved now - https://github.com/spring-projects/spring-hateoas/issues/169.

As you have mentioned above in your first attempt - resources.add(linkTo(methodOn(Controller.class).method(null)).withRel("rel")
should work.

Inhumation answered 2/3, 2017 at 18:23 Comment(0)
M
3

This isn't currently a part of spring-hateoas, see this open bug report, which suggests adding this functionality to ControllerLinkBuilder and this previous question which has an answer with a custom implementation for doing this.

Maple answered 25/3, 2015 at 12:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.