Skip to content

Commit

Permalink
🔨 BASE #270 exemplo funcional
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinaldo Araujo Barreto Junior committed Jul 6, 2022
1 parent e87bff2 commit 4f5c463
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
12 changes: 7 additions & 5 deletions appexemplo_v2.0/api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
require_once $current_dirApi.DS.'autoload_appev2_api.php';

//--------------------------------------------------------------------------------
require_once $current_dirApi.DS.'env.php';
require_once $current_dirApi.DS.'basicAuth.php';
require_once $current_dirApi.DS.'jwtAuth.php';
require_once $current_dirApi.DS.'slimConfiguration.php';
require_once $current_dirApi.DS.'routes.php';
//require_once $current_dirApi.DS.'env.php';
//require_once $current_dirApi.DS.'basicAuth.php';
//require_once $current_dirApi.DS.'jwtAuth.php';
//require_once $current_dirApi.DS.'slimConfiguration.php';
//require_once $current_dirApi.DS.'routes.php';

require_once $current_dirApi.DS.'routes2.php';
45 changes: 45 additions & 0 deletions appexemplo_v2.0/api/routes2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;

/**
* Instantiate App
*
* In order for the factory to work you need to ensure you have installed
* a supported PSR-7 implementation of your choice e.g.: Slim PSR-7 and a supported
* ServerRequest creator (included with Slim PSR-7)
*/
$app = AppFactory::create();

/**
* The routing middleware should be added earlier than the ErrorMiddleware
* Otherwise exceptions thrown from it will not be handled by the middleware
*/
$app->addRoutingMiddleware();

/**
* Add Error Middleware
*
* @param bool $displayErrorDetails -> Should be set to false in production
* @param bool $logErrors -> Parameter is passed to the default ErrorHandler
* @param bool $logErrorDetails -> Display error details in error log
* @param LoggerInterface|null $logger -> Optional PSR-3 Logger
*
* Note: This middleware should be added last. It will not handle any exceptions/errors
* for middleware added after it.
*/
$errorMiddleware = $app->addErrorMiddleware(true, true, true);


$urlChamada = $_SERVER["REQUEST_URI"];
// Define app routes
$app->get($urlChamada, function (Request $request, Response $response, $args) {
$msg = "Hello, mundo";
$msgJson = json_encode($msg);
$response->getBody()->write( $msgJson );
return $response->withHeader('Content-Type', 'application/json');
});

// Run app
$app->run();

0 comments on commit 4f5c463

Please sign in to comment.