-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
78 lines (66 loc) · 1.56 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
$answer = "";
// ROUTES #########################################################################################
if (!$_SERVER['REQUEST_METHOD'])
{
// ToDo: Error handling
http_response_code(405);
echo "Not allowed";
}
switch ($_SERVER['REQUEST_METHOD'])
{
case "GET":
$answer = requestGet();
break;
case "POST":
$answer = requestPost();
break;
case "PUT":
$answer = requestPut();
break;
case "DELETE":
$answer = requestDelete();
break;
default:
$answer = "Unsupported request method.\r\n";
break;
}
echo $answer;
function requestGet()
{
// READ: Get request to fetch data from server
foreach ($_GET as $key => $value)
{
echo $key . ": " . $value . "\r\n";
}
// ToDo: These key value pairs can later be translated to fetch any data or to fetch one specific data entry
http_response_code(200);
return "OK";
}
function requestPost()
{
// CREATE: Post request to create new data on server
foreach ($_POST as $key => $value)
{
echo $key . ": " . $value . "\r\n";
}
// ToDo: These key value pairs can later be translated to create new data on server
http_response_code(201);
return "Created";
}
function requestPut()
{
// UPDATE: Put request to update data on server
// ToDo: Implement database service
// ToDo: Read PUT data using fopen("php://input", "r");
// ToDo: Don't forget to close the data stream!
http_response_code(204);
return "No response";
}
function requestDelete()
{
// DELETE: Delete request to delete data on server
// ToDo: Parse URI to fetch which data to delete
http_response_code(202);
return "Accepted";
}