hugh
hugh

Reputation: 31

Consuming Java RESTFul web service with PHP client

I am having some problems developing a PHP client that will consume Java RESTful services, created in NetBeans 7.1.1.

For those who don't know: When you create a Java RESTful web-service based on MySQL database (entities), NetBeans will create, automatically, the entities class, and each entity "facade", that can be known as a service provider.

I developed a web application using Java RESTful web-service server and the Java RESTful client that consumes the web-services through Jersey & Servlets.

Now on to a planned PHP client: I already googled a lot, and what I see is: no interoperability (or i'm "the" noob), which is one of the purposes of web-services. I know how to create a RESTful web-service in PHP, and communicate with a PHP client, and the same with Java, but what I want is create the Java RESTful web-services server, and a php client.

Sorry if I said something wrong on the subject, and feel free to correct me.

If anyone could help me, giving me some ideas, code examples, explaining the "know-how", I would appreciate a lot.

Upvotes: 2

Views: 5674

Answers (1)

user3199583
user3199583

Reputation: 11

This is rather an easy problem to solve. For an enterprise application, I have modeled this same solution. The Java layer has CXF restful web services mapping to a mixture of SOAP endpoints (external systems) as well as entity objects (mapped via Hibernate/IBatis). Consuming the CXF rest layer is rather simple. In PHP, I would definitely recommend using the Guzzle client.

/** USE REST SERVICES **/

$client = new Client("http://example.com/);

$locationRequest = $client->get('/someservice/rest/location/findstatebyzip.json?zip=12345');
$locationResponse = $locationRequest->send();

$locationResults = json_decode($locationResponse->getBody());

The great thing about Guzzle Client is that you aren't required to have CURL enabled/installed, it can use other transport mechanisms.

Upvotes: 0

Related Questions