PHP Libraries/Classes that helped you easy using REST with JSON? - php

I would like to know what existing PHP libraries/classes have you used for your REST+JSON projects.
If I need to create a wrapper for social engines API such as Facebook and/or Twitter API, what existing PHP REST JSON architecture do you recommend?
JSON CONSUMING DEVICE (not PHP based) <--> PHP REST SERVICE <--> SOCIAL API

If all you need is a RESTful client, then I don't really see why you need a framework at all.
You can use e.g. the curl libraries to do an HTTP request (or even plain sockets), and then json_decode & json_encode for the JSON. That's it. That's your client right there. REST is not more than that.
I'm sure there are wrappers around PHP's curl library that are a little bit more intuitive for the RESTful "I just want to GET/POST/PUT/DELETE some data" approach, but then again it's at most 20 lines of code to roll a class that does that yourself.

Zend Framework has a REST library available, with client and server, as well as the REST route and controller. It also has context switching available, so it's easy to switch output to XML, JSON, or whatever you want if you extend it. There is also a Twitter service available, although I haven't tried it.

Related

Accessing Google App Engine's Search API from PHP

Is there anyway to do this? I've looked in the google-api-php-client library but it's not there yet. Is there any other way or am I out of luck?
The search API is only enabled for Python Java and Go, as Mario pointed out.
I would look into the modules documentation and try to separate your logic. Your search API can be the only module that isn't in PHP. There is no other solution for your problem unfortunately.
The team promised that a REST API would be made available at Google I/O 2011. I haven't been able to find any follow ups since.
https://www.youtube.com/watch?v=7B7FyU9wW8Y#t=2088
You CAN now access the Search API natively from PHP.
The library is in alpha but should make its way to release fairly soon.
It uses the Google Protocol Buffers so it's the same level of abstraction as the Python/Java/Go SDKs
https://github.com/tomwalder/php-appengine-search
Feedback appreciated!
I ran into this problem previously, so wrote a sample PHP+Python module pair to allow access to search via URL fetch to a Python module.
https://github.com/tomwalder/phpne14-text-search
I have a similar scenario as you. This might not be the best solution, but I've solved it as follows:
I've created a Python module using Google Endpoints API to expose a set of methods capable of sending and receiving JSON formatted data via HTTP GET or POST. These methods allow me create Documents and Indexes or do queries.
My PHP client, simply calls these urls and passes appropriate data.
So effectively I have a wrapper around the search API and the python stuff is hidden inside.

Difference between cURL and SOAP in PHP?

I am curious to know about different ways of implementing web services in PHP? Is there other ways except cURL and SOAP? How SOAP is different than cURL? Is there any similarities also between them?
Thanks,
ursitesion
You can implement a web service in PHP with SoapServer or with PHP - return JSON creating a REST interface. There are other ways, such as XML-RPC, but I usually end using either SOAP or REST, I prefer REST whenever possible.
Curl is a tool that you can use to consume a web service, it's not used to create a web service.
REST or SOAP reading that might help.
Probably best to think of cURL as just a way to send a request (eg GET,POST) to another server.
There are alternatives to cURL, including just straight file_get_contents()
Edit : replaced a rotted link. Also, having used SOAP quite a lot since this first reply, I'd add that another main reason you'd prefer SOAP to REST would be if you have to absolutely, positively double check that every transaction was received, else have the opportunity to resend it. No doubt you can do this with a suitably designed REST webservice, but that would need careful design and testing.

Creating a fairly primitive Web Service

We are rolling out one of our services to another service provider in PHP. They have already built the client, it just sends data in a post (no xml/json etc). Our script then processes it and returns an xml string with the response. Also they will need a token authentication system. Because of the fact they are just using cURL to post raw data, I don't think I can use soap/rest/xml-rpc ... can anyone point me to any good tuts etc?
Cheers,
Oauth is a secure and easy to implement for security solution for tokens. And they have libraires for java, php, python, and pretty much any language you can think of.
Very strange (and backwards) they built a client without an existing service. but the important thing is to document the interface between your two systems, and adhere to it.
David Walsh explains a simple php web service that returns JSOn or XML.
http://davidwalsh.name/web-service-php-mysql-xml-json

Create a webservice in Php native

I am new in web service. I was totally confused when seeing examples to create web service in internet. Actually, My client have xml to place the orders. what they want is they need to create a wsdl(web service) to call the xml by their vendor forms. So i need to create a webservice that integrate with xml and vendopform(it may be in any language). How i can do this, my mind has empty now to think this. Can any body help me to sort this issue.
If you're creating a SOAP service (which it sounds like you are, and I feel sorry for you ;)), try starting by looking at PHP's SOAP extension:
http://php.net/manual/en/book.soap.php
If you can create something more RESTful, Ruby on Rails does a good job at allowing you to throw together a quick and dirty web service without too many headaches, but even in PHP you can create RESTful APIs pretty easily.
You can read the HTTP request body via e.g. fgets(STDIN) if your requests will accept XML as a POST/PUT format.
But yes, your question is too broad to provide anything more than nudges towards the tools you might choose to use.

How is cURL related to web services?

well...just about all I needed to say...lookie here, I'm a total noob in web programming so go easy on me..and oh...if ever it is...could you point me to a simple example? i've worked wiht cURL on a payment API (Authorize.net) but I can't seem to get the picture of how it applies to web services
cURL is a library used to retrieve remote URLs.
There are plenty of other ways to do this in PHP, for instance using file_get_contents() but cURL offers much more flexibility.
It doesn't do anything special with web services - all it does is request URLs. Depending on the type of service you're using you might want to look at the PEAR SOAP module, PHP's SOAP classes or PHP's XML-RPC functions.
you can use curl to fetch a url (usually with a post request), and use the data that was fetched in you application.
curl operates as a client or useragent, in much the same way as requesting data from a website would be done from a web browser.
if you are doing strictly get requests there are other simpler was then curl, but curl gives a lot more flexibility, such as reading headers, raw data, etc

Categories