Andy Baird
Andy Baird

Reputation: 6208

Zend Framework app as a web service

I'm developing a zend framework app that's just going to act as a web service. I have no need to ever output HTML at any point in the application and don't even want the overhead of creating empty view files.

I want my app to output XML by default, JSON if requested (via the format parameter would be fine).

Is there any way to do this without explicitly defining the context switching rules in the init() part of every controller?

Upvotes: 0

Views: 1072

Answers (2)

Valentin Bora
Valentin Bora

Reputation: 1

you could try doing the context switch using a Zend_Controller_Front plugin on preDispatch.

Upvotes: 0

Andy Fowler
Andy Fowler

Reputation: 771

If you're going to be providing JSON, SOAP or XML-RPC, you're probably better off using Zend_Json_Server + Zend_Soap_Server instead of Zend_Controller_Action. Both the JSON and SOAP server classes can consume the same server class. No need for the overhead of routing, etc.

Matthew Weier O'Phinney's (Zend FW lead), site has a great post detailing the proper way of doing this: Exposing Service APIs via Zend Framework

Upvotes: 3

Related Questions