-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
59 lines (31 loc) · 977 Bytes
/
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
<?php
require 'vendor/autoload.php';
require 'src/controllers/Countries.php';
function send_json($content)
{
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");
echo json_encode($content);
exit;
}
$app = new \Slim\Slim();
$app->get('/countries/all(/:count(/:page))', function ($count=0, $page=1) {
// Fetch all countries
$Countries = new Countries();
$countries_all = $Countries->getAllCountries($count, $page);
send_json($countries_all);
});
$app->get('/countries/alpha/:alpha', function ($alpha) {
// Fetch country with $alpha code
$Countries = new Countries();
$country = $Countries->getCountryByAlpha($alpha);
send_json($country);
});
$app->get('/countries/name/:name', function ($name) {
// Fetch country with $name
$Countries = new Countries();
$country = $Countries->getCountryByName($name);
send_json($country);
});
$app->run();
?>