You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
878 B

<?php
header('Content-Type: application/json');
include __DIR__ . '/../data/people.php';
if($_REQUEST['action'] === 'index'){
echo json_encode($people);
} else if ($_REQUEST['action'] === 'post'){
$requestBody = file_get_contents('php://input');
$body = json_decode($requestBody);
$zagthar = new Person($body->name, $body->age);
$people[] = $zagthar;
echo json_encode($people);
} else if ($_REQUEST['action'] === 'delete'){
array_splice($people, $_REQUEST['id'], 1);
echo json_encode($people);
} else if ($_REQUEST['action'] === 'update'){
$requestBody = file_get_contents('php://input');
$body = json_decode($requestBody);
$zagthar = new Person($body->name, $body->age);
$people[$_REQUEST['id']] = $zagthar;
echo json_encode($people);
}
?>