Powerful API in Yii

Hi there,

I’m trying to build a powerful API in Yii and is now looking into tweaking CController and CInlineAction a bit. I would like a second opinion on how to do this.

The API should be able to take a request with a $_POST variable called "requests" in order to make multiple actions in one HTTP request:


requests: [


    route: 'user/get/id/1'



    route: 'user/put',

    data: {name: 'some..', email: 'some@email.com'}



And the server should respond with a JSON encoded string with an item for each request.

It would be optimal to keep using Yii for parsing routes, routing to desired controller (maybe using CController::forward) and authentication, but I find it a bit hard to save the return values of the actions. Another problem is that I don’t want to raise exceptions if an action is not found. It should produce an error in the returned JSON, but all other requests shouldn’t be affected.

What do you think? Thanks!

I struggled with this a few years ago. Check out my extension library (http://github.com/Pogostick/ps-yii-extensions) and look at the CPSRestController. Works good for my API needs.