-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathexample.php
More file actions
53 lines (46 loc) · 1.45 KB
/
example.php
File metadata and controls
53 lines (46 loc) · 1.45 KB
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
<?php
require 'src/Nanite.php';
require 'src/functions.php';
get('/', function () {
?>
<h1>Nanite Example</h1>
<h2>Post</h2>
<form action="<?= $_SERVER['PHP_SELF'] ?>?<?= baseUri('/test') ?>" method="post">
<input type="text" name="name" />
<button type="submit">Submit</button>
</form>
<h2>Put</h2>
<form action="<?= $_SERVER['PHP_SELF'] ?>?<?= baseUri('/test') ?>" method="post">
<input type="hidden" name="_method" value="PUT" />
<input type="text" name="name" />
<button type="submit">Submit</button>
</form>
<h2>Patch</h2>
<form action="<?= $_SERVER['PHP_SELF'] ?>?<?= baseUri('/test') ?>" method="post">
<input type="hidden" name="_method" value="PATCH" />
<input type="text" name="name" />
<button type="submit">Submit</button>
</form>
<h2>Delete</h2>
<form action="<?= $_SERVER['PHP_SELF'] ?>?<?= baseUri('/123/delete') ?>" method="post">
<input type="hidden" name="_method" value="DELETE" />
<button type="submit">Delete</button>
</form>
<?php
});
get('/test', function () {
echo "Test page";
});
post('/test', function () {
$name = empty($_POST['name']) ? 'World' : $_POST['name'];
echo "Hello, {$name}";
});
put('/test', function () {
echo 'Put: ' . $_POST['name'];
});
patch('/test', function () {
echo 'Patch: ' . $_POST['name'];
});
delete('/([0-9]+)/delete', function ($id) {
echo "Deleted: {$id}";
});