DELETE method returns GET when endpoint ends with '/'

34 views Asked by At

Currently using codeigniter 4.4.6 for my restapi. What I wanted is to be also able to delete multiple records using an array from raw json body and from the index function. So I want to distinguish the method used to perform get or delete functions.

I've set my $autoRoute = true; and added routes

$routes->delete('blog', 'blog');
$routes->get('blog', 'blog');
$routes->resource('blog');

I'm checking http method in my index() using

$this->respond($_SERVER['REQUEST_METHOD']);

My problem is when my endpoint ends in '/' it will return GET method instead of DELETE. Here's an example result using the code above:

http://localhost/blog   postman method set to DELETE returns 'DELETE' method
http://localhost/blog   postman method set to GET returns 'GET' method
http://localhost/blog/  postman method set to DELETE returns 'GET' method
0

There are 0 answers