JaxRS location header response
reminder ·Add @Context UriInfo uriInfo
to your method:
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.core.Context;
...
public Response create(
@NotNull RequestHttpModel request,
@Context UriInfo uriInfo
){
...
}
Use method getRequestUriBuilder()
from uriInfo
to add to the path
the id
of the new resource.
...
var locationHeader = uriInfo.getRequestUriBuilder().path(id).build()
...
Add this location header to the Response
...
return Response.create(locationHEader).build();
...