Add IfExists parameter for Routes to define if a second Route should Error, Overwrite or be Skipped #1042
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
Adds a new
-IfExists
parameter toAdd-PodeRoute
,Add-PodeStaticRoute
, andAdd-PodeSignalRoute
- including the relevant Group functions likeAdd-PodeRouteGroup
. This parameter takes the values Default, Error, Overwrite, and Skip. (the default behaviour is Error, as it currently is)The same parameter has also been added onto
Use-PodeRoutes
, meaning you can applySkip
to all Routes on mass:Furthermore, there's also a new
Set-PodeRouteIfExistsPreference
function which let's you overwrite the global default behaviour of Error:In the case of the options:
The default value that is used is defined by the following hierarchy:
Add-PodeRoute
)Add-PodeRouteGroup
)Use-PodeRoute
Set-PodeRouteIfExistsPreference
This also adds 3 new Test functions:
Test-PodeRoute
Test-PodeStaticRoute
Test-PodeSignalRoute
Related Issue
Resolves #964
Examples
To Skip over creating a Route that already exists:
Running the above, and calling
http://localhost:8090/
will return the result of1
not2
😄. If you swapSkip
toOverwrite
and re-run, you'll get the result of2
instead!