API Design

This commit is contained in:
Yuan Chiu 2014-11-09 20:19:09 +08:00
parent ccdca161db
commit 3208dfdf96
4 changed files with 91 additions and 4 deletions

View File

@ -0,0 +1,10 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>沒有此選項</title>
</head>
<body>
<h1>拍謝喔!沒有這樣的東東~</h1>
</body>
</html>

View File

@ -0,0 +1,24 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>API</title>
</head>
<body>
<header>
<h1>UElearning API</h1>
<h2>Version 2.0</h2>
</header>
<div id="contain">
<section id="details">
<ul>
<li></li>
</ul>
</section>
</div>
</body>
</html>

View File

@ -2,12 +2,64 @@
require_once __DIR__.'/../../config.php';
require UELEARNING_ROOT.'/vendor/autoload.php';
$app = new \Slim\Slim();
$app = new \Slim\Slim(array(
'templates.path' => './json'
));
$app->get('/', function () {
echo "Test";
$app->get('/', function () use ($app) {
$requestType = $app->request->headers->get('Accept');
if(strpos($requestType, 'text/html') !== FALSE) {
include('html/index.html');
}
else {
$app->view(new \JsonApiView());
$app->add(new \JsonApiMiddleware());
$app->render(200, array(
'title' => '',
'version' => '2.0'
));
}
});
$app->notFound(function () use ($app) {
$requestType = $app->request->headers->get('Accept');
if(strpos($requestType, 'text/html') !== FALSE) {
include('html/404.html');
}
else {
$app->view(new \JsonApiView());
$app->add(new \JsonApiMiddleware());
$app->render(404,array(
'error' => TRUE,
'message' => 'user not found'
));
}
});
$app->error(function (\Exception $e) use ($app) {
//$app->render('error.php');
});
$app->group('/Users', function () use ($app) {
$app->get('/:user_id', function ($user_id) {
echo "Hello, $user_id";
});
});
$app->group('/UTokens', function () use ($app) {
$app->get('/:token', function ($token) {
echo "Login Token: $token";
});
});
// Say hello!~~~
$app->get('/hello/:name', function ($name) {
echo "Hello, $name";
});

View File

@ -8,6 +8,7 @@
}
],
"require": {
"slim/slim": "2.*"
"slim/slim": "2.*",
"entomb/slim-json-api": "dev-master"
}
}