It is common scenario to search same resource using same data type as PathVariable (for example String).
If I had resource named Student like:
class Student {
String name;
String email;
...
}
So, both name and email are Strings.
How would I create 2 endpoints to get information about this student by name or by email in Spring Boot?
I would like to have something like this:
@GetMapping(path="/{name}
public StudentResponse getStudentByName(@PathVariable String name) {...}
and
@GetMapping(path="/{email}
public StudentResponse getStudentByEmail(@PathVariable String email) {...}
, but this leads to ambiguous endpoint since these 2 endpoints receive same parameter types.
How would I create endpoints in such case?
I assume my path would have to be different or to have different data types of its PathVariable to avoid ambiguous endpoint. But given that this scenario is quite common case, what is recommended way to do it?