first routing

master
Juan 3 years ago
parent fd47c40bf3
commit ceb93028ac

@ -1,6 +1,7 @@
<?php <?php
header('Content-type: text/plain;charset=utf-8'); //header('Content-type: text/plain;charset=utf-8');
//print_r($_SERVER); header('Content-type: application/json;charset=utf-8');
$vars=array();
foreach(array('REQUEST_METHOD', foreach(array('REQUEST_METHOD',
'REDIRECT_URL', 'REDIRECT_URL',
'QUERY_STRING', 'QUERY_STRING',
@ -8,8 +9,46 @@
'REQUEST_TIME_FLOAT', 'REQUEST_TIME_FLOAT',
'REQUEST_TIME') as $key) 'REQUEST_TIME') as $key)
{ {
echo "\n[".$key."] = ".$_SERVER[$key]; if(isset($_SERVER[$key]))
{
$vars[$key] = $_SERVER[$key];
}
else
{
$vars[$key] = "";
}
} }
//echo json_encode($vars);
$query = preg_replace("/^\/api/","",$vars['REDIRECT_URL']);
//echo $query;
switch($query)
{
case "/toto/" :
case "/test/" :
header('HTTP/1.1 200 OK');
echo json_encode( (object) array('status'=>'active') );
break;
case "/key/" :
if($vars['REQUEST_METHOD'] == "POST")
{
}
else
{
header('HTTP/1.1 405 Method Not Allowed');
echo json_encode( (object) array('error'=>'/key/ requires POST method') );
}
break;
default :
// header('HTTP/1.1 404 Not Found');
header('HTTP/1.1 501 Not Implemented');
echo json_encode( (object) array('error'=>'This path has not been implemented') );
break;
}

Loading…
Cancel
Save