Yii Framework Forum: Creating An Api - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Creating An Api Rate Topic: -----

#1 User is offline   jhouse153 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 10-January 13
  • Location:Salt Lake City, UT

Posted 11 January 2013 - 01:18 PM

Ok, I know this may seem like a question with many different answers, but I want to get some idea as to how to proceed.

I'm developing an API. The API will receive and send XML. The message types and how to respond are defined by a value inside the XML. So, when I receive an XML post, I will parse through the XML, and find the appropriate response.

I would like to set up the API so that the clients only need to post to one page. (i.e. example.com/api/). My system will then determine the type of XML request, and respond appropriately.

My question is, (I'm new to MVC, so please excuse the ignorance), would I just route every request to one controller that will interpret the XML and then execute the appropriate code? If so, how do I adjust the urlManager to route all post requests to the ApiController class? Or would I use a routes.php for this?

Let me know if this doesn't make sense and I will try and clarify. Thanks in advance.

#2 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 589
  • Joined: 26-November 10
  • Location:Sialkot, Pakistan

Posted 11 January 2013 - 01:36 PM

You need to set url in config/main.php (or based on your settings) under UrlManager

Actually, Yii automatically uses default url as index.php?r=api (in your current case) and index.php?r=api/getpost in case you have an action getPost in api controller.
Cheap Domain & Hosting - Web & App Design - Web Application Development

My Page

#3 User is offline   Davey 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 125
  • Joined: 14-September 11

Posted 11 January 2013 - 02:50 PM

I think you should create a API controller with different actions for the different type of API requests (i.e. post/update/delete etc.). So your client can send a post request to index.php?r=api/post (or api/post), where 'api' is your controller. You process all data in the 'post' action and give back a proper response (in any format you want off course).

A little more info about the MVC design pattern can be found here: http://www.yiiframew...1/en/basics.mvc

You can set more friendly URL's in config/main.php like PeRoChAk sais, more info about that can be found here:

Share this topic:

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users