0

I have 2 endpoints as shown below, but I cannot use the endpoint urls like this:

@GetMapping("/{email}")
public ResponseEntity<Void> findByEmail(@PathVariable String email) {
}
@GetMapping("/{id}")
public ResponseEntity<Void> findById(@PathVariable long id) {
}

Should I use something like @GetMapping("mail/{email}") ?

Jack
  • 1
  • 21
  • 118
  • 236
  • Start with something like [this](https://stackoverflow.com/questions/5020704/how-to-design-restful-search-filtering). Whatever approach is taken, be consistent! – Andrew S Mar 24 '23 at 13:50

1 Answers1

0

Yes, using a different path for each endpoint is a good way to avoid conflicts. You can use @GetMapping annotation with a unique path for each endpoint, for example @GetMapping("/email/{email}") for findByEmail method and @GetMapping("/id/{id}") for findById method.

Therefore, when a request comes in as URL /{email} or /{id}, the Spring framework can distinguish between these two endpoints based on different path values.

Feel free
  • 758
  • 5
  • 15