Arno
Arno

Reputation: 147

Get progress status of a REST web service

I have a web page that calls a REST web service to a Java remote server and I would like to get the progress of the process. I use jQuery ajax asynchronously to call my web service from my web page. How can I achieve that?

my REST web service looks like this :

    @PostMapping("/main/postData")
    public String postData(@RequestParam("values") String values)
    {
       //process data
       //update a global variable with status
    }

I have tried to create a variable in a Service class that is updated by my web service in various steps of the process. Then a second web service that returns the value of that variable. But how to call in a loop with Ajax that second web service at the exact same time as the first?

(I don't know if it's a good way, it was just an idea)

Upvotes: 0

Views: 869

Answers (1)

Yousuf Khan
Yousuf Khan

Reputation: 334

You said you've 2 end points, 1 to call the process and a second one to check the progress of the process. You need something like following:

var x = setInterval(() => {
    fetch('/progressOfProcess').then(function(result) {
        //log current progress
        console.log(result)
    })
}, 1000)

fetch('/yourMainProcess').then(function() {
    clearInterval(x)
})

Upvotes: 1

Related Questions