The easiest RPC client method in PHP

I was asked to help another company open a web application. I have a very limited time, and I reluctantly accepted the request under one condition. Since most of the logic continues in the background, I suggested finishing the full back-end only , allowing the external developer to simply interact with my backend.

I plan to make a back-end in Java EE or Python (using Pylons). This does not matter at the moment. I plan that my back-end is completely ready and verified using the module, so my input is unlikely to be needed after my work.

I know that they have a PHP programmer, but as far as I can tell, he is a real rookie. I want him to mainly interact with my backend services in the simplest way, without the ability to "stuff" it. This is basically a CRUD application.

I could implement the backend as accessible through a web service such as XML-RPC or SOAP. Maybe even a RESTful API.

However, my main goal is to make something that the complete PHP "noob" programmer can easily interact without getting confused. I don’t even want to talk with him, because I usually have a very busy schedule, and doing “support calls” is not what I’m ready to do. Which approach to choose? I would welcome any suggestions and materials!

+4
source share
3 answers

I personally would choose the REST API, possibly with a JSON response. SOAP and XML can be a little cumbersome for simple services, and even the most novice web developer understands the concept of accessing the base URL, even if they don't bully the general concept of REST. There are many ways to work with URLs in PHP, so I'm sure they can come up with something, even if it was a hacking problem and not a good client package.

I will also most likely choose JSON encoding and decoding, as it is usually quite simple, while parsing XML can be a bit more complicated.

I would also write at least some basic documentation for the service, regardless of which formats you choose. Otherwise, you will not escape support calls. Your target consumer should have a link to the remote actions available to him or a method for detecting these actions. It will probably take you 10 minutes to crack the sample code when it is ready, and these 10 minutes can save you a lot of emails.

+5
source

Definitely go for a vacation-like implementation and return the result of query string formatting.

Just remember that php will turn the array as variables into an array on the php side.

Take the query string for your options

Input: p1=v1&p2=v2....

Output: output1=var1&output[0]=var2;output[2]=var3

Access to this in php is then as simple as

 <? $request['myparam1'] = param; ... $webService ="http://path.to.service?".http_build_query($request); parse_str(file_get_contents($webService),$response); // response is now an array with you response parameters in it // $response['responseParam1'], reponse['responseParam1'] etc ?> 
+2
source

Been there, done it.

The backend in Django, a PHP interface using the "we make pages" contractor. I hacked a REST-like API using JSON, provided them with a couple of 5-line PHP functions to access my service as a keystore.

After several false starts (where they tried to create a scheme with far-fetched and redirected instead of using the functions that I sent them), they received it, and after that everything went smoothly.

+2
source

Source: https://habr.com/ru/post/1307719/


All Articles