Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.