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

Add support for grouping Routes #976

Merged
merged 3 commits into from
Jun 2, 2022
Merged

Add support for grouping Routes #976

merged 3 commits into from
Jun 2, 2022

Conversation

Badgerati
Copy link
Owner

Description of the Change

Adds support for grouping Routes, to make it easier to give multiple routes shared data - such as middleware, auth, base paths, etc.

This has been added for Routes, Static Routes, and Signal Routes:

  • Add-PodeRouteGroup
  • Add-PodeStaticRouteGroup
  • Add-PodeSignalRouteGroup

Examples

For example, the below will add 3 Routes which all share a /api base path; some Basic authentication, and some other middleware:

$mid = New-PodeMiddleware -ScriptBlock {
    'some middleware being run' | Out-Default
}
Add-PodeRouteGroup -Path '/api' -Authentication Basic -Middleware $mid -Routes {
    Add-PodeRoute -Method Get -Path '/route1' -ScriptBlock {
        Write-PodeJsonResponse -Value @{ ID = 1 }
    }
    Add-PodeRoute -Method Get -Path '/route2' -ScriptBlock {
        Write-PodeJsonResponse -Value @{ ID = 2 }
    }
    Add-PodeRoute -Method Get -Path '/route3' -ScriptBlock {
        Write-PodeJsonResponse -Value @{ ID = 3 }
    }
}

When run, you'll have 3 Routes that all need some Basic authentication at /api/route1, /api/route2, and /api/route3.

@Badgerati Badgerati added this to the 2.7.0 milestone Jun 1, 2022
@Badgerati Badgerati self-assigned this Jun 1, 2022
@Badgerati Badgerati merged commit 6bcb44a into develop Jun 2, 2022
@Badgerati Badgerati deleted the route-group branch June 2, 2022 16:00
@Badgerati Badgerati mentioned this pull request Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant