Web Services – How Much Data Should Be Required in a Request?

web services

When recieving data from clients how much data that you provided to them should you require back from them?

For example when clients order a product from a webservice should they just need to provide a product code? The other alternative would be to require the product code product name and product price ect.

I have alway built webservices the former way with the minimum of data returned back to me, however I have just been consuming another web service that requires the vast majority of the data returned back to them. What are the advantages of the second way?

Best Answer

The Zen masters of Web Services would say:

Require the absolute minimum amount of data required to fill out the request.

Reply with as much data as might be useful to a requester.

The reason being that extra data requires extra (and unnecessary) work on the client side an introduces more overhead and more bugs. Sending "too much" data in the reply is generally only a little extra work for the server, it requires no effort for the client to ignore any fields it does not currently need, and, it reduces the number of change requests over the long term. In this way your API will be easier to use and useful to as wide an audience as possible.