Home > Software engineering >  Spring boot How to prevent multi requests coming from the front-end side?
Spring boot How to prevent multi requests coming from the front-end side?

Time:10-31

Is there a way to prevent multi requests from the postman or any other client to the spring boot application?

I mean, I can run a for-loop in Ajax as an example and send lots of requests to my controller. how can I prevent that?

CodePudding user response:

One way to achieve that is like below,

Create a request filter or interceptor in the spring boot project, and then save the request IP address in a cache server like radis for a predefined time. and then when a request comes, extract the IP address from the request and compare it with the values in the cache, if the value exists, you can return the request before reaching it to the controller, if there is no entry for that IP address in radis, you can save that IP address in radis and parse that request to the controller

https://www.baeldung.com/spring-boot-add-filter

CodePudding user response:

Very good Question, you need to use circuit breaker to handle that. It will allow you to limit connections if server is down, and after several attempts it will not allow any request. This happens with a use of a fallback method, which will reply immediately to the client, hence, clearing the thread and make your application faster.

checkout my implementation of this in GitHub

feel free to add feedback or comment in GitHub

  • Related