Skip to content

Instantly share code, notes, and snippets.

@torgro
Last active February 17, 2018 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torgro/dc68cef4917933261f5fb45b6fe9a688 to your computer and use it in GitHub Desktop.
Save torgro/dc68cef4917933261f5fb45b6fe9a688 to your computer and use it in GitHub Desktop.
function Get-FileApi
{
[cmdletbinding()]
Param(
[Parameter(Mandatory)]
[hashtable]
$Authorization
,
[string]
$Name
)
$invokeSplat = @{
Uri = "http://localhost:11000/api/file"
Method = "Get"
}
$headersSplat = @{
Headers = @{
Authorization = $Authorization.Authorization
}
}
if (-not [string]::IsNullOrEmpty($Name))
{
$headersSplat.Headers.Name = $Name
}
$respons = Invoke-RestMethod @invokeSplat @headersSplat
if ($respons.error)
{
throw $respons.error.message
}
if ($respons.StatusCode -eq 200)
{
$respons.Content | ConvertFrom-Json
}
else
{
Write-Error -Message "Respons was not successfull, StatusCode is [$($respons.StatusCode)]" -ErrorAction Stop
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment