Skip to content

Instantly share code, notes, and snippets.

@digimon1740
Created April 24, 2020 17:33
Show Gist options
  • Save digimon1740/9920d2794450c348d25e48e404bd36fd to your computer and use it in GitHub Desktop.
Save digimon1740/9920d2794450c348d25e48e404bd36fd to your computer and use it in GitHub Desktop.
using ResponseEntity on Spring WebFlux
@RestController
public class UserController {
private UserService userService;
public UserController(UserService userService) {
this.userService = userService;
}
@GetMapping("/users/{userId}")
public Mono<ResponseEntity<User>> get(@PathVariable Long userId) {
Mono<User> userMono = userService.getById(userId);
return userMono.map((user) -> {
if (user.isAdult()) {
return ResponseEntity.ok().header("X-User-Adult", "true").build();
}
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment