ben
ben

Reputation: 93

spring boot - how to stop the backend rest api processing after the frontend is closed

I'm using spring boot to create a restful backend application and the frontend is using vue. When someone sends a rest request to my backend application via my frontend webpage, is it possible to stop the backend processing thread after the webpage or the web browser is closed?

Upvotes: 9

Views: 10695

Answers (1)

CGS
CGS

Reputation: 2872

HTTP Request cannot be cancelled. General guideline is, the REST calls should be very short. If in case, your REST calls are long running, recommendation is to break into granular calls.

If that is not an option and if you want to cancel a back-end processing, following option can be tried

  • For every back-end call, return a job id using which server can uniquely identify and return it to the client

  • Detect browser close

  • Expose a new Service to cancel based on the Unique Job Id
  • Handle logic in Server

This will require considerable amount of change!

Upvotes: 5

Related Questions