In Azure functions the http request is parsed from a $req JSON object like so
# POST method: $req
$requestBody = Get-Content $req -Raw | ConvertFrom-Json
I am finding it very difficult (coming from powershell ISE as a sys admin) to get the exact structure of this variable, for example, this is the default run.ps1 whenever a PowerShell function is created
# POST method: $req
$requestBody = Get-Content $req -Raw | ConvertFrom-Json
$name = $requestBody.name
# GET method: each querystring parameter is its own variable
if ($req_query_name)
{
$name = $req_query_name
}
Out-File -Encoding Ascii -FilePath $res -inputObject "Hello $name"
so if the http method is POST $name = $requestBody.name
if it's GET $name = $req_query_name
how to I access the rest of the request such as the http headers, user agent timestamps etc?
for example this is not well documented and would have been nice to know, especially if dealing with a large amount of query params
if ($req_method -eq 'GET'){
something with GET
}
if ($req_method -eq 'POST'){
something with POST
}
this led me on a guessing game, $req_headers? - nope $req_context? nope My question is how can I find out everything about the incoming request? why are variable names $req_something or $req_something_something - what is this structure?
Get-Variable
to get a list of all variables in the session, and$var | Get-Member
to see all properties on a variable. – Dhruv Murarka$var | Out-String
). Make that part of the function code itself, and return it as the function's response, or log it, or store it to a file, etc. – Dhruv Murarka{"name":"Azure"}
– Sum1sAdmin