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

Proposal for variable routes #67

Open
anddave opened this issue Mar 10, 2022 · 2 comments
Open

Proposal for variable routes #67

anddave opened this issue Mar 10, 2022 · 2 comments

Comments

@anddave
Copy link

anddave commented Mar 10, 2022

Proposal for variable routes

  • As of RestPS 7.0.44 from PSGallery, only hardcoded routes are supported, which is to say that Invoke-RequestRouter selects routes where {$_.RequestURL -eq $RequestURL}.
  • Consequently endpoints like "api/periodictable/{element}" are marginally feasible in small scale only and not feasible in large scale.
  • Proposal: we could add a regex match to Invoke-RequestRouter which would enable variable routes.
  • For the sake of simplicity, I propose that:
    • Map file should only be changed to support regex matching
    • as opposed to adding any more notational load to the map file, let the endpoint scripts do all the interpreting of variable routes beyond matching the regex.
  • Some defensive code and unit testing may need to be added for mitigating the risk of accidental route doubling if a route is both an exact match and a regex match.
  • Branch and PR forthcoming soon
    Thanks @jpsider great module
@jpsider
Copy link
Owner

jpsider commented Mar 10, 2022

Makes sense. I have not had the need to add this up to this point. But in dealing with other API's use this type of thing on a normal basis. I am looking forward to reviewing the PR!

@anddave
Copy link
Author

anddave commented Mar 10, 2022

This is what it looks like when multiple routes match

INFO: Start-RestPSListener: Processing RequestType: GET URL: /periodictable Args:
/RestPS/RestPS/private/Invoke-RequestRouter.ps1:58
Line |
58 | $CommandReturn = . $RequestCommand -RequestArgs $RequestA …
| ~~~~~~~~~~~~~~~
| The term
| '/periodictable/endpoints/GET/Invoke-EndpointPeriodicTable.ps1
| /periodictable/endpoints/GET/Invoke-EndpointPeriodicTable.ps1'
| is not recognized as a name of a cmdlet, function, script
| file, or executable program. Check the spelling of the name,
| or if a path was included, verify that the path is correct and
| try again.

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

No branches or pull requests

2 participants