-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.php
57 lines (39 loc) · 1.41 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
<?php
declare(strict_types=1);
use midorikocak\nano\Api;
require __DIR__ . '/vendor/autoload.php';
$api = new Api();
$message = 'Welcome to Nano';
$api->get('/', function () use ($message) {
echo json_encode(['message' => $message], JSON_THROW_ON_ERROR, 512);
http_response_code(200);
});
$api->post('/', function () use ($message) {
$input = (array)json_decode(file_get_contents('php://input'), true, 512, JSON_THROW_ON_ERROR);
echo json_encode($input, JSON_THROW_ON_ERROR, 512);
http_response_code(201);
});
$api->get('/echo/{$message}', function ($message) {
echo json_encode(['message' => $message], JSON_THROW_ON_ERROR, 512);
http_response_code(200);
});
$authFunction = function ($username, $password) {
return ($username == 'username' && $password == 'password');
};
$api->auth(function () use (&$api) {
$api->get('/entries/{id}', function ($id) {
echo json_encode(['id' => $id], JSON_THROW_ON_ERROR, 512);
http_response_code(201);
});
$api->post('/entries/{id}', function ($id) {
echo json_encode(['id' => $id], JSON_THROW_ON_ERROR, 512);
http_response_code(201);
});
$api->put('/entries/{id}', function ($id) {
echo json_encode(['id' => $id], JSON_THROW_ON_ERROR, 512);
http_response_code(204);
});
$api->delete('/entries/{id}', function ($id) {
http_response_code(204);
});
}, $authFunction);