Open cstayyab opened 3 years ago
Now we can provide arbitrary and multiple parameters name in URL Path.
$app->get( 'user/:username/pictures/:id', function ($req, $res) { $res->json($req); } );
This will output the resultant Request Object in JSON format where we can see the params array providing username and id
params
username
id
{ "app": { "router": {} }, "body": [], "cookies": [], "files": [], "hostname": "localhost", "ip": "::1", "method": "GET", "originalUrl": "/user/cstayyab/pictures/2", "params": { "username": "cstayyab", "id": "2" }, "path": "user/cstayyab/pictures/2", "port": "80", "protocol": "HTTP/1.1", "query": [], "route": "", "scheme": "http", "secure": false, "session": null, "xhr": 0 }
In future we can provide an option to pass custom regex expression like this:
$app->get( 'user/:username([A-Za-z0-9_]+)/pictures/:id([0-9]+)', function ($req, $res) { $res->json($req); } );
Fixes #3
@riverside Can you please review and merge it so it can be published and used from composer?
Now we can provide arbitrary and multiple parameters name in URL Path.
Example
This will output the resultant Request Object in JSON format where we can see the
params
array providingusername
andid
Future Work
In future we can provide an option to pass custom regex expression like this:
Fixes #3