Php – the best way to exchange files via authenticated web service

PHPweb services

I'm not so much looking for code (although if you want to link to tutorials it would be appreciated) as I am trying to get an idea of what people in the know are doing. Our system is written in PHP.

As part of an Electronic Medical Record System, I need to be able to securely exchange documents (Word, PDF, etc.) with business partners. I also need to transmit identifying information with the documents (patient name, medical record number, etc.)

If I Google exchanging files in a web service, I am given a bunch of information about a variety of methods. But, what's not easy to see is how old the information is, how commonly the methods are used, and if there is something out there that if I just knew what I was looking for, would blow my socks off.

TLDR – If you were going to use a web service to exchange files, and your system was written in PHP, how would you go about doing it, and why?

Best Answer

Use https and REST. Its secure, tested, and works on any platform. We have two formats that uses a file extension of either .xml or .json for easy consumption, when performing either a POST or GET request. we have http headers that identify if POST is actual a PUT, POST, or DELETE request since not all clients/servers/firewalls allow/recognize PUT and/or DELETE.

One gotcha with using REST is defining an API. The natural tendency is to use a uri style that mimics the familar RPC style. You need to work backwards, and define your uri with the object(s) being acted upon first, and use the verbs (GET,PUT,POST,DELETE) for your operations.

SOAP in comparison has more features, but about 95%(a measure I pulled out of the air) of the features are never used. It complicates understanding it, and adds overhead to development. I would only recommend using it if REST did not provide you with everything you need.