Skip to content

Instantly share code, notes, and snippets.

@philsturgeon
Created June 3, 2009 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philsturgeon/123003 to your computer and use it in GitHub Desktop.
Save philsturgeon/123003 to your computer and use it in GitHub Desktop.
<?php
require(APPPATH.'/libraries/REST_Controller.php');
class Example_api extends REST_Controller {
function user_get()
{
//$user = $this->some_model->getSomething( $this->get('id') );
$user = array('id' => $this->get('id'), 'name' => 'Some Guy', 'email' => 'example@example.com');
if($user)
{
$this->response($user, 200); // 200 being the HTTP response code
}
else
{
$this->response(NULL, 404);
}
}
function user_delete()
{
//$this->some_model->deletesomething( $this->get('id') );
$message = array('id' => $this->get('id'), 'message' => 'DELETED!');
$this->response($message, 200); // 200 being the HTTP response code
}
function users_get()
{
//$users = $this->some_model->getSomething( $this->get('limit') );
$users = array(
array('id' => 1, 'name' => 'Some Guy', 'email' => 'example1@example.com'),
array('id' => 2, 'name' => 'Person Face', 'email' => 'example2@example.com'),
array('id' => 3, 'name' => 'Scotty', 'email' => 'example3@example.com'),
);
if($users)
{
$this->response($users, 200); // 200 being the HTTP response code
}
else
{
$this->response(NULL, 404);
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment