예제 #1
0
});
/*
HTTP POST http://domain/api/tasks
REQUEST Body
{
  "description": "Learn REST",
}

RESPONSE 200 OK Body
Learn REST added
*/
$app->post('/tasks/', function () use($app) {
    $taskJson = $app->request()->getBody();
    $newTask = json_decode($taskJson, true);
    if ($newTask) {
        $task = TaskService::add($newTask);
        echo "Task {$task['description']} added";
    } else {
        $app->response->setStatus(400);
        echo "Malformat JSON";
    }
});
/*
HTTP PUT http://domain/api/tasks/1
REQUEST Body
{
  "id": 1,
  "description": "Learn REST",
  "done": false
}
예제 #2
0
	"name": "Lidy Segura",
	"email": "*****@*****.**"
}

RESPONSE 200 OK 
{
  "name": "Thiis is a test",
  "email": "*****@*****.**",
  "id": "1"
}
*/
$app->post('/guests/', function () use($app) {
    $taskJson = $app->request()->getBody();
    $newTask = json_decode($taskJson, true);
    if ($newTask) {
        $guests = TaskService::add($newTask);
        echo json_encode($guests);
    } else {
        $app->response->setStatus(400);
        echo "Malformat JSON";
    }
});
/*
HTTP DELETE /api/guests/:id
RESPONSE 200 OK 
{
  "status": "true",
  "message": "Guest deleted!"
}

HTTP DELETE /api/guests/x