Yii Framework Forum: Best Practise For Big Rest Apis - Yii Framework Forum

Jump to content

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

Best Practise For Big Rest Apis Modular version of the REST API example? Rate Topic: -----

#1 User is offline   Bravolito 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 09-August 12
  • Location:Berlin (Germany)

Posted 15 November 2012 - 05:14 AM

I read the Wiki post about creating a REST service with Yii. (http://www.yiiframew...ate-a-rest-api/) and apart from that this solution is significantly more complex than creating a SOAP service I am woundering how to create a big webservice that is using a lot of models.

Following the example the code from the Wiki post, the REST API controller is blowing up more and more (what probably is not improving the performance and memory usage behaviour of PHP)

Does somebody have a charmant solution for building a "very big" REST API in Yii?

My current solution is to make controllers with the 5 functions for every model and reference them in the ApiController.. But somehow this solution seems to be a little "dirty" so i am yelling for professional help.. ;)

Has somebody a nice idea?

Example :

	public function loadCtrl( $ModelName )
		switch( strtolower( $ModelName ) )
 			case 'model1' :
 				return new ApiPartialModel1();
		// Model not implemented error
		$this->_sendResponse(501, sprintf(
				'Error: Mode <b>list</b> is not implemented for model <b>%s</b>',
				$_GET['model']) );

	public function actionView()
		$Ctl = $this->loadCtrl( $_GET['model']);
		$Res = $Ctl->actionView();
		// Did we get some results?
		if(empty($Res)) {
			// No
					sprintf('No items where found for model <b>%s</b>', $_GET['model']) );
		} else {
			// Prepare response
			$rows = array();
			foreach($Res as $model)
				$rows[] = $model->attributes;
			// Send the response
			$this->_sendResponse(200, CJSON::encode($rows));


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