AftabHussain

Untitled

Oct 20th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Need a better function name!
  2. function Import-WebRoutes {
  3.     [cmdbletbinding()]
  4.     Param(
  5.         [string[]]$CmdletList
  6.     )
  7.  
  8.     foreach ($cmdlet in $CmdletList) {
  9.         $properties = Get-Command -Name $cmdlet
  10.         $verb = $properties.Verb
  11.         $noun = $properties.Noun
  12.         # Waiting for POST support to figure out what to do with the parameters
  13.         $parameters = (Get-Command Get-Item).Parameters.Values | Select-Object Name, ParameterType, SwitchParameter
  14.  
  15.         # the default is an issue, need to be able to provide a way for a specific http method to be defined for unrecognised verbs
  16.         Switch ($properties.Verb) {
  17.             'New' { $verb = 'Post' }
  18.             'Set' { $verb = 'Patch' }
  19.             'Delete' { $verb = 'Delete' }
  20.             default { $verb = 'Get'}
  21.         }
  22.  
  23.         New-WebRoute -Path "/$noun" -Method $Verb -ScriptBlock {
  24.             param($request,$response)
  25.  
  26.             $params = $request.QueryParameters
  27.             $result = & $cmdlet @params
  28.  
  29.             $response.Send($Result)
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment