You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can you give me a hint on what me be changed so that the route parameters are enclosed in {} and question marks can be used to make it optional just like in Laravel.
Line 97 of tree.go is probably a good place to start for changing the :token style to {token}. You can look for a { character instead and then filter out the ? and/or } at the end of the token too.
Adding the optional capability is a little more complex. The current system just returns the final node from addPath, and then the Handle function adds the handler to the returned node. The simplest possibility would be to change addPath to take the verb, handler function, and addSlash as arguments, and update the nodes appropriately as they go. Then when you see a ? in the next token, you can just call n.setHandler(verb, handler) to set the handler on the current node in addition to setting it on the child node.
I wasn't sure from the questions If you want regexes or not, since the examples you gave use them but you didn't mention them otherwise. The data structure used by httptreemux doesn't lend itself well to regexes, although you could probably have a special node type for it. But there are some frameworks that already support regexes too which would be a better choice.
Hi Daniel,
Can you give me a hint on what me be changed so that the route parameters are enclosed in {} and question marks can be used to make it optional just like in Laravel.
http://laravel.com/docs/4.2/routing#route-parameters
Route::get('user/{id}', function($id)
{
return 'User '.$id;
});
Optional Route Parameters
Route::get('user/{name?}', function($name = null)
{
return $name;
});
Optional Route Parameters With Defaults
Route::get('user/{name?}', function($name = 'John')
{
return $name;
});
Regular Expression Route Constraints
Route::get('user/{name}', function($name)
{
//
})
->where('name', '[A-Za-z]+');
Route::get('user/{id}', function($id)
{
//
})
->where('id', '[0-9]+');
The text was updated successfully, but these errors were encountered: