Can you show me your code which is actually calling the API?
waitForResource actually just waits for resources that are invoked by page itself or by casperjs manually. This can be done to implement some kind of loop in which you will call API every 5 seconds and assert that the API will respond with 200 or 201.
edit:
First of you need to know how much time should you wait for resource to be in your database. Take the maximum time you calculated it could take. Then write function which will iterate over API call something like this.
var condition = false;
function loop(index,iteration){
if(condition) {
return;
}
else if(index >= iteration) {
casper.test.fail('Record not found');
return;
}
casper.then(function(){
this.thenOpen('http://www.webpage.com/api/record/543',function(response){
if(response.status==200) {
condition = true;
this.test.pass("Record found");
}
this.echo(response.status);
})
})
.then(function(){
loop.call(this,index+1,iteration)
})
}
casper.test.begin('Test for record',1,function suite(test){
casper.start()
loop.call(this, 0, 20);
casper.run(function(){
test.done();
})
})
If you need to leverage calls because of high traffic just use setTimeout.