forked from ClubeDosGeeksCoding/api-php-slim-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
59 lines (41 loc) · 1.36 KB
/
index.php
File metadata and controls
59 lines (41 loc) · 1.36 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
54
55
56
57
58
59
<?php
//Autoload
$loader = require 'vendor/autoload.php';
//configuracoes para exibir erros no SLim, pode ser comentado, apenas para localhost
$configuration = [
'settings' => [
'displayErrorDetails' => true,
],
];
//Instanciando objeto
$app = new \Slim\App($configuration);
//quando não é chamado nenhum método
$app->get('/', function() {
echo "Nenhum método foi chamado";
});
//Listando todas
$app->get('/pessoas/', function() {
//$this->response->withJson() transforma o output em json e manda o header correto
return $this->response->withJson((new \controllers\Pessoa())->lista(),201);
});
//get pessoa
$app->get('/pessoas/{id}', function( $request , $response , $args ) {
$id = $args['id'];
return $response->withJson( (new \controllers\Pessoa())->get($id) );
});
//nova pessoa
$app->post('/pessoas/', function( $request, $response ) use ( $app ) {
return $response->withJson( (new \controllers\Pessoa($app))->nova() );
});
//edita pessoa
$app->put('/pessoas/{id}', function( $request, $response, $args ) use ( $app ) {
$id = $args['id'];
return $response->withJson( (new \controllers\Pessoa($app))->editar($id) );
});
//apaga pessoa
$app->delete('/pessoas/{id}', function( $request, $response, $args ) {
$id = $args['id'];
return $response->withJson( (new \controllers\Pessoa())->excluir($id) );
});
//Rodando aplicação
$app->run();