Skip to content

Conversation

cstayyab
Copy link

@cstayyab cstayyab commented Sep 3, 2020

Now we can provide arbitrary and multiple parameters name in URL Path.

Example

$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

{
  "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
}

Future Work

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

@cstayyab
Copy link
Author

cstayyab commented Sep 9, 2020

@riverside Can you please review and merge it so it can be published and used from composer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Question] How to pass Custom Parameters inside URL

1 participant