Skip to content

Instantly share code, notes, and snippets.

@Stephanevg
Last active September 24, 2019 06:05
Show Gist options
  • Save Stephanevg/0d40bdea736a46e65e07a855cb5f2779 to your computer and use it in GitHub Desktop.
Save Stephanevg/0d40bdea736a46e65e07a855cb5f2779 to your computer and use it in GitHub Desktop.
Import-module Polaris -force
# Using a script block
New-PolarisPostRoute -Path "/Pcc" -ScriptBlock {
$json = $Request.Body
$comp = $json.computerName
$FileName = $Json.FileName
$return = $comp + $FileName
$response.Send($return)
} -Force
New-PolarisGetRoute -Path '/get' -Scriptblock {
$Response.send('plop')
}
# Using a script path
Start-Polaris -UseJsonBodyParserMiddleware -Verbose
<#
Code call for testing:
$Data = @{
FileName = 'plop.ps1'
ComputerName = $Env:computerNAme
PackageName = 'plop'
RunTime = '1.4.5'
}
$JsonBody = $Data | ConvertTo-Json
#both ways here freen
Invoke-RestMethod -Method post -Uri http://localhost:8080/Pcc -Body $Jsonbody -ContentType 'application/json' -verbose
@ChendrayanV
Copy link

Okay - Try this!

New-PolarisPostRoute -Path "/Pcc" -ScriptBlock {
    $Response.SetContentType('application/json')
    $Request.Body = $Request.BodyString | ConvertFrom-Json
    $Response.send(($Request.Body | ConvertTo-Json))
}

Now, your client request

$Data = @{
    FileName = 'plop.ps1'
    ComputerName = $Env:computerNAme
    PackageName = 'plop'
    RunTime = '1.4.5'
    
} | ConvertTo-Json

Invoke-RestMethod -Method post -Uri http://localhost:8080/Pcc -Body $Data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment