2

Can Zend_Rest_Server return Json ? If not, what are the alternatives ( other lib suggestions are ok also)

Charles
  • 50,943
  • 13
  • 104
  • 142
johnlemon
  • 20,761
  • 42
  • 119
  • 178
  • Zend_Rest_Server is deprecated, you should use Zend_Rest_Controller et al instead. Also see [Examples of building a REST API server using Zend Framework?](http://stackoverflow.com/questions/5312762/examples-of-building-a-rest-api-server-using-zend-framework/5313068#5313068). – wimvds Mar 17 '11 at 10:37

1 Answers1

3

Zend_Rest_Server outputs XML, eventhough not clearly specified in the documentation.

There are some alternatives:

You could leverage the whole MVC architecture given by Zend Framework, thanks to Zend_Rest_Route and Zend_Rest_Controller.
You will find a complete example here:
http://techchorus.net/create-restful-applications-using-zend-framework

Again, the example displays plain string, but using json_encode, or Zend_Json::encode should return json.

And finally, a complete (advanced) example that use the ContextSwitch feature:
http://www.chrisdanielson.com/2009/09/02/creating-a-php-rest-api-using-the-zend-framework/

(If you need more information on ContextSwitch Action Helper, please refer to the documentation.)

Unfortunately, my limited reputation prevent me from giving you more links, but Google is your friend using some magic words such as zend rest json or zend controller rest json ...

ant1j
  • 305
  • 2
  • 18
  • Zend_Rest_Server is only working with XML. You can't decide the ouput format. – johnlemon Mar 17 '11 at 04:47
  • After some testing, I have edited my answer as the initial example was not working. I have not fully tested it, but the Zend_Rest_Controller and ContextSwitch should (must) be working ... – ant1j Mar 17 '11 at 10:22