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

Stop pointlessly passing the WebEvent argument #618

Closed
Badgerati opened this issue Oct 15, 2020 · 0 comments · Fixed by #621
Closed

Stop pointlessly passing the WebEvent argument #618

Badgerati opened this issue Oct 15, 2020 · 0 comments · Fixed by #621

Comments

@Badgerati
Copy link
Owner

In Pode there is the WebEvent, which contains all of the Request, Response, Header, Cookie, etc info for a current web request. This WebEvent is then typically supplied to Routes, Middleware, etc as a first default parameter:

Add-PodeRoute -Method Get -Path '/' -ScriptBlock {
    param($e)
    Write-PodeJsonResponse -Value @{ Message = "Hello, $($e.Query['name'])" }
}

However, it's actually possible to just use $WebEvent.Query['name']!

Add-PodeRoute -Method Get -Path '/' -ScriptBlock {
    Write-PodeJsonResponse -Value @{ Message = "Hello, $($WebEvent.Query['name'])" }
}

The above works exactly the same, and works in Routes, Middleware, and Authentication (Method, Validator, and Post-Validator - each of which don't have it supplied at the moment!)

The docs will need a big clean-up, but it should make routes cleaner not having to constantly do param($e).

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

Successfully merging a pull request may close this issue.

1 participant