@GetMapping(value = "/employees/detailed", produces = MediaTypes.HAL_JSON_VALUE) public ResponseEntity<Resources<Resource<EmployeeWithManager>>> findAllDetailedEmployees() { return ResponseEntity.ok( employeeWithManagerResourceAssembler.toResources( StreamSupport.stream(repository.findAll().spliterator(), false) .map(EmployeeWithManager::new) .collect(Collectors.toList()))); }
@GetMapping(value = "/employees", produces = MediaTypes.HAL_JSON_VALUE) public Resources<Resource<Employee>> findAll() { return assembler.toResources(repository.findAll()); }
@GetMapping(value = "/employees", produces = MediaTypes.HAL_JSON_VALUE) public Resources<Resource<Employee>> findAll() { return assembler.toResources(repository.findAll()); }
/** * Look up all employees, and transform them into a REST collection resource using * {@link EmployeeResourceAssembler#toResources(Iterable)}. Then return them through * Spring Web's {@link ResponseEntity} fluent API. * * NOTE: cURL will fetch things as HAL JSON directly, but browsers issue a different * default accept header, which allows XML to get requested first, so "produces" * forces it to HAL JSON for all clients. */ @GetMapping(value = "/employees", produces = MediaTypes.HAL_JSON_VALUE) public ResponseEntity<Resources<Resource<Employee>>> findAll() { return ResponseEntity.ok( assembler.toResources(repository.findAll())); }
/** * Look up all employees, and transform them into a REST collection resource using * {@link EmployeeResourceAssembler#toResources(Iterable)}. Then return them through * Spring Web's {@link ResponseEntity} fluent API. * * NOTE: cURL will fetch things as HAL JSON directly, but browsers issue a different * default accept header, which allows XML to get requested first, so "produces" * forces it to HAL JSON for all clients. */ @GetMapping(value = "/employees", produces = MediaTypes.HAL_JSON_VALUE) public ResponseEntity<Resources<Resource<Employee>>> findAll() { return ResponseEntity.ok( assembler.toResources(repository.findAll())); }
/** * Look up all employees, and transform them into a REST collection resource. * Then return them through Spring Web's {@link ResponseEntity} fluent API. * * NOTE: cURL will fetch things as HAL JSON directly, but browsers issue a different * default accept header, which allows XML to get requested first, so "produces" * forces it to HAL JSON for all clients. */ @GetMapping(value = "/employees", produces = MediaTypes.HAL_JSON_VALUE) ResponseEntity<Resources<Resource<Employee>>> findAll() { List<Resource<Employee>> employees = StreamSupport.stream(repository.findAll().spliterator(), false) .map(employee -> new Resource<>(employee, linkTo(methodOn(EmployeeController.class).findOne(employee.getId())).withSelfRel(), linkTo(methodOn(EmployeeController.class).findAll()).withRel("employees"))) .collect(Collectors.toList()); return ResponseEntity.ok( new Resources<>(employees, linkTo(methodOn(EmployeeController.class).findAll()).withSelfRel())); }
@GetMapping("/employees") ResponseEntity<Resources<Resource<Employee>>> findAll() { List<Resource<Employee>> employeeResources = StreamSupport.stream(repository.findAll().spliterator(), false) .map(employee -> new Resource<>(employee, linkTo(methodOn(EmployeeController.class).findOne(employee.getId())).withSelfRel() .andAffordance(afford(methodOn(EmployeeController.class).updateEmployee(null, employee.getId()))) .andAffordance(afford(methodOn(EmployeeController.class).deleteEmployee(employee.getId()))), linkTo(methodOn(EmployeeController.class).findAll()).withRel("employees") )) .collect(Collectors.toList()); return ResponseEntity.ok(new Resources<>(employeeResources, linkTo(methodOn(EmployeeController.class).findAll()).withSelfRel() .andAffordance(afford(methodOn(EmployeeController.class).newEmployee(null))))); }