Spring rest endpoint heirarchy

32 Views Asked by At

I have 2 endpoints @RestMapping("/endpoint1") & @RestMapping("/endpoint1/subpoint1") but am unable to change this such that I can have @RestMapping("/endpoint1") and then @RestMapping("/subpoint1") so that subpoint1 is still "/endpoint1/subpoint1"?

1

There are 1 best solutions below

0
Ranjan On

Based on my understanding I tried a sample in my local with the same. Can you please try the below code once. Both will work

http://localhost:8080/endpoint1 
http://localhost:8080/endpoint1/subpoint1
@RestController
@RequestMapping("/endpoint1")
public class Controller{    
    
    @GetMapping
    public String endPoint1()   
    {  
        return "COMES > /endpoint1";  
    } 
    
    @GetMapping("/subpoint1")
    public String getSubPoint()   
    {  
        return "COMES > /endpoint1/subpoint1";  
    }  

}