RESTful Web Services with Spring Framework Part-2

GET http://localhost:8080/users
@GetMapping(path = "/{userId}")
public String getUser(@PathVariable String userId) {
return "GET user method got called with user " + userId;
}
http://localhost:8080/users/3
GET request with user
@GetMapping()
public String getUsers ( @RequestParam(value = "page") int page,@RequestParam(value = "limit") int limit)
{
return "get user method got called with page number = " + page + " with limit = " + limit;
}
http://localhost:8080/users?page=2&limit=50
GET request with pagination and its limit
http://localhost:8080/users?page=2
MissingParameter
DefaultValue Parameter
@GetMapping()
public String getUsers(@RequestParam(value="page",required=false) int page,@RequestParam(value="limit")int limit)
{
return "get user method got called with page number = "+ page +" with limit = " +limit ;
}
http://localhost:8080/users?limit=50
required with primitive data types
@GetMapping()
public String getUsers(@RequestParam(value="page",defaultValue= "1",required=false) int page,@RequestParam(value="limit")int limit,@RequestParam(value="status",required = false)String status)
{
return "get user method got called with page number = "+ page +" with limit = " +limit +" status is " +status ;
}
http://localhost:8080/users?limit=50
Required with the default and non-primitive type

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store