Lets say I receive an xml request that is sent to my web service and this request contains some data in it such as Hotel Room/Rate pairs (Room = Double Queen, Rate = 10%). The database has all of these Room/Rate pairs stored, so when the xml request comes in, I have to validate them to see if the request contains both the room and the rate in the database. If I receive one room/rate pair and it is not in the database, I fail the message and send back an error response, but if I receive 3 room/rate pairs for example, and 2 are found in the database, but one is not, I would process the succussfull ones and send back warnings for the ones that were not found. The other scenario is if I receive 3 room/rate pair and they all are not found in the database, then I want to send back an error message. What is the best way to approach these scenarios?
My opinion is that you should be consistent and always follow the same path regardless of the number of data you have in the request. That way the client of your application knows what to expect. As such, being consistent leaves you only with two choices:
- strict: you are very strict and nothing goes through if you have one error (like, this is a transaction). You stop at the first error and return the response explaining where you find the first error.
- permissive: The valid rooms are successfully updated. For each room you don't have in your database, you generate a warning and continue. The response will contain a warning for each problematic data.
From what I understand it does not seem you require your request to be transactional (everything passes, or nothing) so my guess is that you may be "permissive". The client should check the warnings and do whatever it can to do better next time.
There is also a third choice, but I don't know if you can implement that into your business domain: why not "create" the missing rooms in the database if you don't have them ?