Skip to content

Instantly share code, notes, and snippets.

@marckean
Created May 2, 2019 01:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marckean/d8350cf267434953ff520f9c5ccf1181 to your computer and use it in GitHub Desktop.
Save marckean/d8350cf267434953ff520f9c5ccf1181 to your computer and use it in GitHub Desktop.
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."
# Interact with query parameters or the body of the request.
$FirstName = $Request.Query.FirstName # Query based parameters
if (-not $FirstName) {$FirstName = $Request.Body.FirstName} # JSON Body (POST)
if (-not $FirstName) {$FirstName = $Request.Params.FirstName} # Route Template
$Surname = $Request.Query.Surname # Query based parameters
if (-not $Surname) {$Surname = $Request.Body.Surname} # JSON Body (POST)
if (-not $Surname) {$Surname = $Request.Params.Surname} # Route Template
if ($FirstName -and $Surname) {
$status = [HttpStatusCode]::OK
$body = "Hello $FirstName" + " $Surname"
}
else {
$status = [HttpStatusCode]::BadRequest
$body = "Please pass a name on the query string or in the request body."
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $status
Body = $body
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment