Skip to content

Instantly share code, notes, and snippets.

@gregturn
Created July 27, 2017 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregturn/16b875ef35b1cfb2a6641285f9f4441d to your computer and use it in GitHub Desktop.
Save gregturn/16b875ef35b1cfb2a6641285f9f4441d to your computer and use it in GitHub Desktop.
@GetMapping("/employees/{id}")
public Resource<Employee> findOne(@PathVariable String id) {
// Start the affordance with the "self" link, i.e. this method.
Link findOneLink =
linkTo(methodOn(EmployeeController.class).findOne(id)).withSelfRel();
// Define final link as means to find entire collection.
Link employeesLink = linkTo(methodOn(EmployeeController.class).all()).withRel("employees");
// Return the affordance + a link back to the entire collection resource.
return new Resource<Employee>(
EMPLOYEES.get(Integer.parseInt(id)),
findOneLink
.withAffordances(byLink(
linkTo(methodOn(EmployeeController.class).updateEmployee(null, id)).withRel("put")))
.withAffordances(byLink(
linkTo(methodOn(EmployeeController.class).partiallyUpdateEmployee(null, id)).withRel("patch"))),
employeesLink);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment