Search code examples
javarestjax-rshateoas

HATEOAS Link using UriBuilder


I have a REST service defined as below:

@Path("/v1/employee/")
EmployeeService {

@Path("/designation/")
public void listDesignation() {

}
}

My goal is to generate the relative URL "v1/employee/designation/".

If I use UriBuilder.fromResource(EmployeeService.class), it gives me "/v1/employee/"

And if i use UriBuilder.fromMethod(EmployeeService.class, "listDesignation"), it gives me "/designation"

Does anyone know how I can I get relative URL "v1/employee/designation" without doing any hard coding.

Thanks in advance.


Solution

  • You can use your UriBuilder#fromResource(Class), then chain a call to path(Class, String) (class, method name) or path(String) (actual path) or path(Method) (actual method if you have it).