Implementing rest api for default controller behaviour

Hello All,

As i am new to yii , so i have raised this discussion. Also i did not find any help from the previous discussions.

I am building an application in which it is divided into two parts i.e web-app & api’s. If the request to my application comes from the web-app than the response should render a specific view file with some business logic written inside the respective actions. But if the request is from the api than it should accept the data in form of json and give a response too in the form of json. But the problem is that i dont have to write the separate controllers for handling the request that comes to the api’s.

So i was just looking for a solutions by which i could create a separate layer at the top by which my same controller could handle both the api request’s and the web-app request and give the response respectively.

Please help me asap as i am stuck in my project.