I have created two POST services in nodeJS express
- http://localhost:3001 - This service has body request {order:"123"} with method POST & setTimeout for 5000
- http://localhost:3001/details - This service doesn't have any body request or setTimeout
Both above service give a response
- First Response is : Order Code:123
- Second Response is JSON of Order Details: {'Date':'2020-05-12', 'amount':'20'}
I have to create a React JS app to fetch both the services. But I require that when we call both services simultaneously, the second service shouldn't wait for the first service to complete.
Below is my call for the service in REACT JS
const loadOrders = () =>{
fetch("http://localhost:3001",{
method:'POST',
body: JSON.stringify({orderReferenceCode: 'GBP-000237453'}),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(res => (res.ok ? res : Promise.reject(res)))
.then(res => res.json())
}
const loadOrdersDetails = () =>{
fetch("http://localhost:3001/details",{
method:'POST',
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(res => (res.ok ? res : Promise.reject(res)))
.then(res => res.json())
}
What can I do to async this call's???
loadOrdersDetailswithout waiting forloadOrders? What if the first POST fails and the order doesn't get created? What order details will you be posting afterwards? Again, I have no idea about your application, but it seems to me that you need an "orderCode" to POST the orderDetails, if not you don't know which order the details belong to.