Routing, and http verb (or http method) #1110

roberto-butti opened this Issue Mar 3, 2012 · 6 comments


None yet

4 participants


I'm going to implement a new rounting functionality.
In application/config/routes.php the developers can define routing rules such as:

$route['product/:num'] = "catalog/product_lookup";

This rule has 1 input: the URL and 1 output the action in a specific controller.
I would like to introduce the HTTP method in the routing rules for example:

$route['test'] = array();
$route['test']["GET"] = "welcome/gethttp";
$route['test']["POST"] = "welcome/posthttp";

For backward compatibility, the rules:

$route['test'] = "welcome/index";

is still valid and the system/core/Router.php will check if the rules is a string i follow the normal behaviour, if is array i will check also the HTTP method.

What do you think about tihs?


I'm checking the code of Router.php.
Maybe the best way to define a verb keyword in the key of the array $route like this (or something else)

$route[':GET:/test'] = "welcome/gethttp";
$route[':POST:/test'] = "welcome/gethttp";

I don't know. I'm going on study the code of Router.php and later i will be able to take a decision (maybe) :)


ok, there is my pull request. The patch is here: roberto-butti@4d788ce

narfbg commented Oct 31, 2012

In the meantime (or unless nothing similar to this is implemented), #1636 might help you in creating any type of route.


I've always preferred how @philsturgeon's REST server library did it.

Rather than messing around with routes you just suffix your controller method with _post, _put or _delete

pveyes commented Oct 31, 2013

I tried implementing HTTP verb in routing using array index, here's my pull request

narfbg commented Nov 12, 2013

Implemented via #2712.

@narfbg narfbg closed this Nov 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment