Created
July 27, 2017 22:48
-
-
Save gregturn/16b875ef35b1cfb2a6641285f9f4441d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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