Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Arbitrary Parameters match from Path #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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