🚧 This template is new and may contain bugs
This is an OpenFAAS language template for a PowerShell based http function using the Polaris web server.
Functions built with this template will respond to GET
and POST
requests. These requests will be handled by handler.ps1
. For now, this is where you need to add your custom logic.
By default the Polaris Request
and Response
objects are globally available and can be consumed by your custom handler.
The following properties are globally available in the $Request
object.
RawRequest
BodyString
AcceptTypes
Cookies
Headers
Method
Query
Url
UserAgent
ClientIP
User
NOTE: The Polaris server is initialized with
UseJsonBodyParserMiddleware
. As a result a new property calledBody
is available in the request object. This is a deserialized version ofBodyString
and can be accessed like this:$Request.Body.MyProperty
Refer to the source code for more information.
The following methods are globally available in the $Response
object.
Send
SendBytes
Json
SetHeader
SetStatusCode
SetContentType
SetStream
GetContentType
Refer to the source code for more information.
Name | Default | Description |
---|---|---|
POLARIS_CUSTOM_ROUTE | / | A custom path to append to the server root |
An out of the box build from this template will give you the following:
- A
GET
route at / that responds withHello! Welcome to openfaas-powershell-polaris
- A
POST
route at / that expects a json string with a name property and will respond withHello <name>! Welcome to openfaas-powershell-polaris
- A
GET
route at /status that resonds with some basic information such asthe version of both PowerShell and the Polaris module running in the container.
Create a new directory and pull the template
mkdir faas
cd faas
faas-cli template pull https://github.com/chelnak/openfaas-powershell-polaris
Initialize a new function
faas-cli new --lang powershell-polaris polaris-example --prefix <docker_username>
Modify the stack file, if required. E.g. to add the POLARIS_CUSTOM_ROUTE
environment variable
Build, push and deploy the function
faas-cli up -f polaris-example.yml
Assuming that you are running OpenFAAS in Kubernetes and have a port-forward set up to the gateway service on port 8080 you can test the function like this:
Invoke-RestMethod -Method GET -Uri http://localhost:8080/function/polaris-example/status
Contributions of any kind welcome.