0

We would like to transfer a XML to a WEB API that can accept text as well as binary data. What is the best way to transfer it in terms of traffic size?

Is it better to transfer it as clear text or as Stream of Binary data?

Omtechguy
  • 3,321
  • 7
  • 37
  • 71

1 Answers1

1

If you are concerned that the XML data you want to transfer is too large, then you can try using compression, gzip compression being the most popular. Web API has some built-in functionality for this but you could also "roll your own" if you like, for example if you want a different compression algorithm.

Fortunately, there's plenty of code around to help with compressing and decompressing your data stream. Take a look at the following:

Finally, you could consider using Expect: 100-Continue. If an API client is about to send a request with a large entity body, like a POST, PUT, or PATCH, they can send “Expect: 100-continue” in their HTTP headers, and wait for a “100 Continue” response before sending their entity body. This allows the API server to verify much of the validity of the request before wasting bandwidth to return an error response (such as a 401 or a 403). Supporting this functionality is not very common, but it can improve API responsiveness and reduce bandwidth in some scenarios. (RFC2616 §8.2.3).

While I appreciate an answer full of links can be problematic if those links go out-of-date or get deleted, explaining Web API compression here is just too large a subject. I hope my answer steers you in a useful direction.

Community
  • 1
  • 1
djikay
  • 10,450
  • 8
  • 41
  • 52
  • Thanks for your detailed answer. in Addition, Could you please let me know if its true that Binary of the same string has smaller size than the string itself? – Omtechguy Jun 30 '14 at 08:29
  • At the lowest level, all data is transferred in binary form, as 0s and 1s, so I'm not sure what you mean. If you compress the data stream, then it will almost certainly be smaller size than if you transfer the text uncompressed. But other than that, I don't believe there's any significant difference. – djikay Jun 30 '14 at 09:35