I currently have a button which sends a request, waits for the full response, and then displays the response body in a text box. Because the response can take up to 2 minutes to complete (but produces output throughout the duration of the request), I would like to stream the response body as it becomes available. Is this possible in Corvid?
My current code is:
import {fetch} from 'wix-fetch';
export function onClick(event, $w) {
//Add here the URL of the CRM API , the method type is "post"
$w("#button").disable();
$w("#outputbox").value = "";
fetch('https://some.external.service/',
{method: 'post',
body: $w("#inputbox").value,
crossDomain: true}
)
.then( (httpResponse) => {
if (httpResponse.ok) {
return httpResponse.text();
} else {
Promise.reject("Fetch did not succeed");
return "Failed to contact server."; }
} )
.then(text => {
$w("#outputbox").value = text;
$w("#button").enable();
})
.catch(err => console.log(err));
}
Thank you!