Welcome Guest, Not a member yet? Register   Sign In
API requests with a trailing forward slash
#1

(This post was last modified: 07-15-2020, 08:47 AM by ogomez.)

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
Reply
#2

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

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.
Reply
#4

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

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




Theme © iAndrew 2016 - Forum software by © MyBB