| | 1 | | <# |
| | 2 | | .SYNOPSIS |
| | 3 | | Tests if a route exists in the Kestrun host. |
| | 4 | | .DESCRIPTION |
| | 5 | | This function checks if a specific route is defined in the Kestrun host's routing table. |
| | 6 | | .PARAMETER Pattern |
| | 7 | | The path of the route to test. |
| | 8 | | .PARAMETER Verbs |
| | 9 | | The HTTP verb(s) to test for the route. |
| | 10 | | .EXAMPLE |
| | 11 | | Test-KrRoute -Path "/api/test" -Verbs "GET" |
| | 12 | | # Tests if a GET route exists for "/api/test". |
| | 13 | | .EXAMPLE |
| | 14 | | Test-KrRoute -Path "/api/test" -Verbs "POST" |
| | 15 | | # Tests if a POST route exists for "/api/test". |
| | 16 | | .NOTES |
| | 17 | | This function is part of the Kestrun PowerShell module and is used to manage routes. |
| | 18 | | #> |
| | 19 | | function Test-KrRoute { |
| | 20 | | [KestrunRuntimeApi('Everywhere')] |
| | 21 | | [CmdletBinding()] |
| | 22 | | [OutputType([bool])] |
| | 23 | | param( |
| | 24 | | [Parameter(Mandatory)] |
| | 25 | | [alias('Path')] |
| | 26 | | [string]$Pattern, |
| | 27 | |
|
| | 28 | | [Parameter()] |
| 0 | 29 | | [Kestrun.Utilities.HttpVerb[]]$Verbs = @([Kestrun.Utilities.HttpVerb]::Get) |
| | 30 | | ) |
| | 31 | | # Ensure the server instance is resolved |
| 1 | 32 | | $Server = Resolve-KestrunServer -Server $Server |
| 1 | 33 | | if ($null -eq $Server) { |
| 0 | 34 | | throw 'Server is not initialized. Please ensure the server is configured before setting options.' |
| | 35 | | } |
| | 36 | |
|
| 1 | 37 | | return [Kestrun.Hosting.KestrunHostMapExtensions]::MapExists($Server, $Pattern, $Verbs) |
| | 38 | | } |
| | 39 | |
|