Reputation: 21
How do I do sequential call to API’s – Example before I Insert to the database, I must show the message to the user if they entered the same key information.
first GET API to check if the record is there in the database
That GET API throws an exception if there is no record, so I must catch that exception and Call the POST API in the same call.
If there is a record in the database, it would get the data and I have display message that similar key information is already existing in the database
Pseudocode
Data existingData = null;
Try {
existingData = this.service.findData(key Information);
If (existingData != null ) {
Show message;
}
Catch (Exception dataNotFound) {
this.service.save(newData);
}
Upvotes: 1
Views: 50
Reputation: 254
I don't think you have to make multiple Http calls for this one. In the end, you want to check if a key exists on the DB - if it doesn't - save the new key. In my opinion, you have to make one http call and handle that logic in the server.
Upvotes: 1