Files
cwsvJudo/homepage/participo/api/shiai.php
2024-01-07 18:36:43 +01:00

55 lines
1.1 KiB
PHP

<?php
require_once("inc/bootstrap.php");
require_once("participoLib/shiai.php");
$method = $_SERVER['REQUEST_METHOD'];
// Sending Response
// - we send a json-formatted response
header("Content-Type: application/json");
// - check if an valid api key was send
authorize();
// - depending on the method we perform different actions
switch($method){
// Create
case 'POST':
$postData = json_decode(file_get_contents('php://input'), true);
if(!$postData){
die(json_encode([
'error'=>$postData . " not valid json data!"
]));
}
die(json_encode(
Shiai::fromArray($postData)->asArray()
));
break;
// Read
case 'GET':
echo(json_encode(
Shiai::dbSelect()
));
break;
// Update
case 'PUT':
die(json_encode([
'success'=>false,
'reason'=>$method.".not supported yet."
]));
break;
// Delete
case 'DELETE':
die(json_encode([
'success'=>false,
'reason'=>$method.".not supported yet."
]));
break;
// all other methods not supported
default:
die(json_encode([
'success'=>false,
'reason'=>$method.".not supported."
]));
}
?>