I am developing a Spring Boot Rest API that handles many inbound requests. My controller is something like below:
@RestController
public class ApiController {
List<ApiObject> apiDataList;
@RequestMapping(value="/data",produces={MediaType.APPLICATION_JSON_VALUE},method=RequestMethod.GET)
public ResponseEntity<List<ApiObject>> getData(){
List<ApiObject> apiDataList=getApiData();
return new ResponseEntity<List<ApiObject>>(apiDataList,HttpStatus.OK);
}
@ResponseBody
@Async
public List<ApiObject> getApiData(){
List<ApiObject> apiDataList3=new List<ApiObject> ();
return apiDataList3;
}
}
So now I wanted to install ratelimit for each user. Say, each user can request only 5 requests per minute or something like that. How to set a speed limit for each user to make only 5 api calls per minute, and if the user requests more than I can send a 429 answer? Do we need an IP address?
Any help is appreciated.
Ricky source
share