Hello !
I'm building a little and so simple API and I got a strage probleme with my routes.
Here is my route.php:
$app->get('/', function () use ($app) {
return $app->version();
});
$app->group(['prefix' => 'api/v1','namespace' => 'App\Http\Controllers'], function($app)
{
$app->get('product','ProductController@getProducts');
$app->get('product/{id}','ProductController@getProduct');
$app->post('product','ProductController@createProduct');
$app->put('product/{id}','ProductController@updateProduct');
$app->delete('product/{id}','ProductController@deleteProduct');
});
In fact, when I sent a GET request on the route: api/v1/product/ it works fine, it's executing the good method (getProducts).
But when I sent a POST request on the same route, it should execute the createProduct method but it's not and use the getProducts method.
The funny fact is that:
This request execute the good method:
POST /api/v1/product/ HTTP/1.1
Host: catalogue.local
label: New productjjj
description: New Product Description
category: 1
price: 889
Cache-Control: no-cache
Postman-Token: 6db161c1-3704-4cd5-ebcd-eef9836016da
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
But this one not: (the difference between both is the "/" missing at the end of product)
POST /api/v1/product HTTP/1.1
Host: catalogue.local
label: New productjjj
description: New Product Description
category: 1
price: 889
Cache-Control: no-cache
Postman-Token: 6db161c1-3704-4cd5-ebcd-eef9836016da
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
I use postman to do my request. I also tested with my shell via curl, same result.
Thanks