diff --git a/htdocs/API/v2/html/404.html b/htdocs/API/v2/html/404.html
new file mode 100644
index 0000000..7158d01
--- /dev/null
+++ b/htdocs/API/v2/html/404.html
@@ -0,0 +1,10 @@
+
+
+
+
+ 沒有此選項
+
+
+ 拍謝喔!沒有這樣的東東~
+
+
diff --git a/htdocs/API/v2/html/index.html b/htdocs/API/v2/html/index.html
new file mode 100644
index 0000000..953dac6
--- /dev/null
+++ b/htdocs/API/v2/html/index.html
@@ -0,0 +1,24 @@
+
+
+
+
+ API
+
+
+
+ UElearning API
+ Version 2.0
+
+
+
+
+
+
diff --git a/htdocs/API/v2/index.php b/htdocs/API/v2/index.php
index 0df290d..6919f2f 100644
--- a/htdocs/API/v2/index.php
+++ b/htdocs/API/v2/index.php
@@ -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";
});
diff --git a/htdocs/composer.json b/htdocs/composer.json
index d1d66a2..22d7c15 100644
--- a/htdocs/composer.json
+++ b/htdocs/composer.json
@@ -8,6 +8,7 @@
}
],
"require": {
- "slim/slim": "2.*"
+ "slim/slim": "2.*",
+ "entomb/slim-json-api": "dev-master"
}
}