Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Need a better function name!
- function Import-WebRoutes {
- [cmdbletbinding()]
- Param(
- [string[]]$CmdletList
- )
- foreach ($cmdlet in $CmdletList) {
- $properties = Get-Command -Name $cmdlet
- $verb = $properties.Verb
- $noun = $properties.Noun
- # Waiting for POST support to figure out what to do with the parameters
- $parameters = (Get-Command Get-Item).Parameters.Values | Select-Object Name, ParameterType, SwitchParameter
- # the default is an issue, need to be able to provide a way for a specific http method to be defined for unrecognised verbs
- Switch ($properties.Verb) {
- 'New' { $verb = 'Post' }
- 'Set' { $verb = 'Patch' }
- 'Delete' { $verb = 'Delete' }
- default { $verb = 'Get'}
- }
- New-WebRoute -Path "/$noun" -Method $Verb -ScriptBlock {
- param($request,$response)
- $params = $request.QueryParameters
- $result = & $cmdlet @params
- $response.Send($Result)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment