API Design
This commit is contained in:
parent
ccdca161db
commit
3208dfdf96
10
htdocs/API/v2/html/404.html
Normal file
10
htdocs/API/v2/html/404.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>沒有此選項</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>拍謝喔!沒有這樣的東東~</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
24
htdocs/API/v2/html/index.html
Normal file
24
htdocs/API/v2/html/index.html
Normal 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>
|
@ -2,12 +2,64 @@
|
|||||||
require_once __DIR__.'/../../config.php';
|
require_once __DIR__.'/../../config.php';
|
||||||
require UELEARNING_ROOT.'/vendor/autoload.php';
|
require UELEARNING_ROOT.'/vendor/autoload.php';
|
||||||
|
|
||||||
$app = new \Slim\Slim();
|
$app = new \Slim\Slim(array(
|
||||||
|
'templates.path' => './json'
|
||||||
|
));
|
||||||
|
|
||||||
$app->get('/', function () {
|
$app->get('/', function () use ($app) {
|
||||||
echo "Test";
|
$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) {
|
$app->get('/hello/:name', function ($name) {
|
||||||
echo "Hello, $name";
|
echo "Hello, $name";
|
||||||
});
|
});
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"slim/slim": "2.*"
|
"slim/slim": "2.*",
|
||||||
|
"entomb/slim-json-api": "dev-master"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user