In a URI, https://www.google.com/items/2 how to get 2 alone (item id) to process further

60 Views Asked by At

In a URI, https://www.google.com/items/2 how to get 2 alone (item id) to process further

1

There are 1 best solutions below

1
LunaLissa On

PATH VARIABLE

Its called PATH VARIABLE, this is just different type of HTTP REQUEST to send parameters within API. In SpringBoot we can use PATH VARIABLE like this :

@RestController
@RequestMapping("car")
public class CarController {

    @Autowired
    CarService carservice;

    @GetMapping("{id}")
    public Car getCarById(@PathVariable long id) {

    return carService.findById(id)
  }
}

Then you can call your api like this and send car id in last url

localhost:8080/car/1