Skip to content

nodakjones/Qcodo-RESTful-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

////////////////////////////////////////////////
// RESTful API for QCODO DEVELOPMENT FRAMEWORK
////////////////////////////////////////////////

This RESTful Qcodo API is really a proof of concept of how this might be integrated into a core in the future.  There are many questions than need to be answered as listed below:

SETUP
1.  in index.php, set the correct include path to prepend.
2.  currently, there is a requirement that either the base or extended orm file has a function called "GetArray" (see example below).  It seemed a bit complicated to get this function generated by codegen, so I go into the extended ORM file and setup how I want the data returned for that particular resource.


USAGE
1.  Get data.  In theory you can now type in /ORMFILE.  This will pull all the records for that resource:
    http://path_to_api/index.php/ORM_FILE
    
2.  Get a specific resource with an key index id. So, if you were accessing a table called Group, it would be: 
    http://path_to_api/index.php/Group/1
    
3.  Get data through qcodo joins. As an example, if you are querying a table called Group, and you have a one-to-many join to Contact, you can access the contact data with:
    http://path_to_api/index.php/Group/1/Contact
    
4.  Get filtered data with QQN.  You can also specify qcodo query nodes (QQN) to filter the data being returned:
    http://path_to_api/Group?Name=GroupName
   
5.  Post data to create a new record.  You can post data to a resource and a new record will be created and the record id will be returned. Or you can update an existing resource record.  There is an included test.php file to test this behavior


TODOS / QUESTIONS:
1.  We are currently are on a Qcodo v3 BETA, so Qcodo v4 might have some compatibility issues? Haven't tested at all yet!
2.  index.php should have the correct include path to prepend.  Is there a better way to do this?
3.  Currently there is no user authentication model setup 
4.  Is there a better way to remove the index.php controller without having to edit the htaccess file? 
5.  Functionality for put and delete are not implemented yet.
6.  Currently, only support for json data return, although xml should be easy to add.
7.  Better way to implement the GetArray function?
8.  Need more elegant handling if primary resource is not found


GET ARRAY EXAMPLE
This goes into the extended ORM files.  The example below is from our Contact ORM.  

public function GetArray()
{
	$arrReturn 		= Array();
	
	foreach($this as $var => $value)
	{
		if (	($var == 'objMailingAddressIDObject' && !is_null($this->MailingAddressID)) ||
				($var == 'objContactTypeIDObject' && !is_null($this->ContactTypeID))
			)
			$arrReturn[substr($var,3)]= $this->{substr($var,3)}->GetArray();
		
		elseif (substr($var,3) == 'CreatedDate' || substr($var,3) == 'LastLoginDate')
		{
			if (is_object($this->{substr($var,3)}))
				$arrReturn[substr($var,3)] = $this->{substr($var,3)}->format('Y-m-d');
		}
		elseif (substr($var,0,1) != '_' && substr($var,0,3) != 'obj' && substr($var,3) != 'Password')
			$arrReturn[substr($var,3)] = $value;		
    }
    return new ArrayIterator($arrReturn);
  			
}

Releases

No releases published

Packages

No packages published

Languages