Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build a templated link?

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");
like image 965
jose_p Avatar asked Mar 23 '15 19:03

jose_p


2 Answers

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.

like image 135
manjunath shetkar Avatar answered Oct 20 '22 22:10

manjunath shetkar


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.

like image 37
beerbajay Avatar answered Oct 20 '22 21:10

beerbajay