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.
27 lines
936 B
27 lines
936 B
<?php
|
|
header('Content-Type: application/json');
|
|
include_once __DIR__ . '/../models/person.php';
|
|
|
|
if($_REQUEST['action'] === 'index'){
|
|
echo json_encode(People::all());
|
|
} else if ($_REQUEST['action'] === 'post'){
|
|
$request_body = file_get_contents('php://input');
|
|
$body_object = json_decode($request_body);
|
|
$new_person = new Person(null, $body_object->name, $body_object->age);
|
|
$all_people = People::create($new_person);
|
|
|
|
echo json_encode($all_people);
|
|
} else if ($_REQUEST['action'] === 'update'){
|
|
$request_body = file_get_contents('php://input');
|
|
$body_object = json_decode($request_body);
|
|
$updated_person = new Person($_REQUEST['id'], $body_object->name, $body_object->age);
|
|
$all_people = People::update($updated_person);
|
|
|
|
echo json_encode($all_people);
|
|
} else if ($_REQUEST['action'] === 'delete'){
|
|
$all_people = People::delete($_REQUEST['id']);
|
|
echo json_encode($all_people);
|
|
}
|
|
|
|
?>
|