From f62015ebdbf3d95a16869e775bbcc82a6e1d90cd Mon Sep 17 00:00:00 2001 From: "dorian.hodin" Date: Wed, 8 Mar 2023 10:52:07 +0100 Subject: [PATCH] Change the method param to a args in URL --- .../API/script/ExceptionHandle/TypeErrorMethod.php | 4 ++-- Source/API/script/index.php | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/API/script/ExceptionHandle/TypeErrorMethod.php b/Source/API/script/ExceptionHandle/TypeErrorMethod.php index 8e62105..4f2fc51 100644 --- a/Source/API/script/ExceptionHandle/TypeErrorMethod.php +++ b/Source/API/script/ExceptionHandle/TypeErrorMethod.php @@ -9,8 +9,8 @@ use Throwable; class TypeErrorMethod extends HttpSpecializedException { protected $code = 400; - protected string $title = "Method query params is not specified"; - protected $message = "Bad Parameters, The API need a 'method' query params in URL. Exemple :'http://url?method=getSomething'"; + protected string $title = "Method is not specified"; + protected $message = "Bad Parameters, The API need a 'method' args in URL. Exemple :'http://url/method=getSomething'"; public function __construct(ServerRequestInterface $request,?Throwable $previous = null) { diff --git a/Source/API/script/index.php b/Source/API/script/index.php index 1a3deb0..0bb79ce 100644 --- a/Source/API/script/index.php +++ b/Source/API/script/index.php @@ -29,14 +29,14 @@ $errorMiddleware = $app->addErrorMiddleware(true, true, true); /** * Add a route for the API */ -$app->get('/', function (Request $request, Response $response) { + +$app->get('/', function (Request $request, Response $response){ + throw new TypeErrorMethod($request); +}); + +$app->get('/{method}', function (Request $request, Response $response, array $args) { $parameters = $request->getQueryParams(); - if (empty($parameters['method'])){ - throw new TypeErrorMethod($request); - }else{ - $method = $parameters['method']; - } - unset($parameters['method']); + $method = $args['method']; $listGateway = array("\\Gateway\\GatewayForm", "\\Gateway\\GatewayKeyword", "\\Gateway\\GatewayQuestion"); $ok = false; foreach ($listGateway as $gateway){