CodeIgniter Forums
API requests with a trailing forward slash - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: API requests with a trailing forward slash (/showthread.php?tid=77022)



API requests with a trailing forward slash - ogomez - 07-12-2020

I spent a lot of time trying to figure out why my routes were not working and found that I needed to exclude the trailing forward slash. Not sure if this is done intentional but just wanted to bring this up in case someone else encounters this issue.

Routes:
PHP Code:
$routes->post('API/news''API\News::create');
$routes->get('API/news''API\News::view'); 

Example:
POST http://localhost/API/news/ will send you to the GET (http://localhost/API/news/view) route
POST http://localhost/API/news will work correctly

Even if I set my route with the trailing forward slash I still get routed to API\news::view. Any insight on this behavior appreciated.

Thanks in advance


RE: API requests with a trailing forward slash - MGatner - 07-15-2020

Seems like a bug. Test it against the latest version on develop branch and if it still an issue open a report on GitHub.


RE: API requests with a trailing forward slash - Jan Zelenka - 07-15-2020

I have encountered this as well. I don't remember exactly but I think from debugging the issue I came to the conclusion it was intentional. Unfortunately I don't have time to search for it now but I believe the code does this explicitly when encountering trailing slash.


RE: API requests with a trailing forward slash - InsiteFX - 07-15-2020

I ran into the way back in a view path with a trailing slash the fix was to escape it \\

Not sure if that is what is happening here tho.


RE: API requests with a trailing forward slash - ogomez - 07-16-2020

I just tested this on 4.0.4 and the issue still exists. I'll put in an issue on github.