Created
June 25, 2012 09:13
-
-
Save ikwattro/2987574 to your computer and use it in GitHub Desktop.
API Root page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function indexAction() | |
{ | |
$buzz = $this->container->get('buzz'); | |
$headers = array( | |
'Accept: application/vnd.com.doggiiz.api+json' | |
); | |
$burl = 'http://localhost/~ikwattro/devapp/web/app_dev.php/front/hello'; | |
$response = $buzz->call($burl, 'GET', $headers); | |
$content = json_decode($response->getContent()); | |
$login = $content->_actions->login->href; | |
//Go to login page : | |
$loginPage = $buzz->get($login); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function indexAction(Request $request) | |
{ | |
$hypermedia = 'application/vnd.com.doggiiz.api+json'; | |
$contentTypes = $request->getAcceptableContentTypes(); | |
if(!in_array($hypermedia, $contentTypes)) | |
{ | |
$response = new Response('None of your Accepted Content Types match one of "'.$hypermedia.'". You have an Accept Header of '.serialize($contentTypes), 406); | |
return $response; | |
} | |
else { | |
$data = array( | |
'message' => 'Welcome to the doggiiz API', | |
'self' => 'http://api.doggiiz.com', | |
'_queries' => array( | |
'dogs' => 'http://api.doggiiz.com/dogs', | |
'breeders' => 'http://api.doggiiz.com/breeders' | |
), | |
'_actions' => array( | |
'login' => array( | |
'href' => 'http://localhost/~ikwattro/devapp/app_dev.php/demo/hello/world', | |
'desc' => 'Go to this page to log into the doggiiz breeder area' | |
) | |
) | |
); | |
$json_data = json_encode($data); | |
$response = new Response($json_data, 200); | |
$response->headers->set('Content-Type', $hypermedia); | |
return $response; | |
} | |
return new Response('', 500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment