Skip to content

Instantly share code, notes, and snippets.

@ikwattro
Created June 25, 2012 09:13
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 ikwattro/2987574 to your computer and use it in GitHub Desktop.
Save ikwattro/2987574 to your computer and use it in GitHub Desktop.
API Root page
<?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);
}
<?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