-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Reinaldo Araujo Barreto Junior
committed
Jul 6, 2022
1 parent
e87bff2
commit 4f5c463
Showing
2 changed files
with
52 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |