If you are already using a MVC framework, like dingo or CI, then implementing a twitter-like api shouldn't be too difficult. For example let's say you have a page URL like so:
The data access (or API) URL could then be something like one of these:
Code:
user/view/evan/xml
user/view/evan/json
You would then have to modify your controller method to see if the user is requesting the regular page or a data API page. So, you could take this user controller:
PHP Code:
class controller
{
public function view($name)
{
// Get data and show page
}
}
And change it to something like this:
PHP Code:
class controller
{
public function view($name,$type='html')
{
// Get data
if($type === 'html')
{
// Show page
}
elseif($type === 'xml')
{
// Show XML version of data
}
elseif($type === 'json')
{
// Show JSON version of data
}
else
{
$this->load->error('404');
}
}
}
I'm sure you could develop some sort of library, helper, or even framework to make this more streamlined, but that's the basic idea. Another idea would be to use the URL router to make API requests go to an entirely different controller.