Created
May 2, 2019 01:49
-
-
Save marckean/d8350cf267434953ff520f9c5ccf1181 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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