-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
76 lines (59 loc) · 1.69 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
<?php
use Bryss\App;
use Bryss\Validator as InputValidator;
require __DIR__ . '/../vendor/autoload.php';
$app = App::create();
// Currently supported methods: GET, POST, PUT, DELETE
$app->get("/hello", function($req, $res, $args){
return $res->json(array(
"message"=>"Hello World",
"author" => "Oyetoke Tobi"
));
});
$app->get('/hello-xml', function($req, $res, $args) {
return $res->xml(array(
"message" => "Hello World",
"author" => "Ilori Stephen A <[email protected]>"
));
});
$app->get("/hello/:name", function($req, $res, $args){
$name = $req->params["name"];
return $res->json(array(
"message"=>"Hello, ".$name
));
});
// Post endpoint with validation
$app->post('/api/v1/register', function($req, $res){
$body = $req->getBody();
$email = $req->input("email");
$password = $req->input("password");
$name = $req->input("name");
$role = $req->input("role", "user");
$validator = InputValidator::schema($body, array(
"email"=>"required|email",
"password"=>"required|min:8",
"name"=>"required|min:2",
));
if(count($validator)!=0){
return $req->json(array(
"status"=>"error",
"message"=>"Validation error",
"errors"=>$validator
), 400);
}
return $res->json(array(
"status"=>"success",
"message"=>"Registration successfull",
"data"=>$body
), 200);
});
$app->put("/api/v1/user", function($req, $res){
return $res->json(array(
"message"=>"PUT method"
));
});
$app->delete("/api/v1/user", function($req, $res){
return $res->json(array(
"message"=>"DELETE method"
));
});