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?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
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:
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 ?
What you probably want to do is to incorporate success/failure in for each request in your response. So, in your example, the user would receive a response saying that the first 2 are successful and the final one failed. Bonus points for including why it failed.