Build REST Service in PowerShell using Polaris

Introduction

The author say that Polaris is “a cross-platform, minimalist web framework for PowerShell.”

This framework allows it to easily build your own RESTful webservice with only PowerShell. Polaris is free, open source, and also written in PowerShell.

The project is hosted on GitHub. Tyler Leonhardt together with Micah Rairdon and other members in the community are maintaining the project actively.

https://github.com/PowerShell/Polaris

Background

The following terms are good to be known when working with REST.

REST

Representational State Transfer (REST) provides a standardized interface commonly used for machine-to-machine communication.

CRUD

CRUD abbreviates Create, Read, Update, and Delete. A (REST) API usually provide these common set of functions.

MAPPING

The process of allocating a HTTP method to a webservice function is called mapping.
the table below shows a common practice:

REST method Webservice function
POST C: Create
GET R: Read
PUT U: Update
DELETE D: Delete

JSON

JavaScript Object Notation (JSON) allows it to conserve structured data like objects, properties, and lists and their relation to each other. Serialization is the procedure to convert virtual objects to be conservable. Deserialization is the other way around. Polaris uses JSON to send and retrieve information, for example:

   “cars”: {


       “car1″:”Ford”,
       “car2″:”BMW”,

PowerShell offers easy handling with ConvertFrom-Json and ConvertTo-Json.

Consumption via Squared Up

The WEB API TILE from Squared Up allows to read data from a REST service and shows it on a Dashboard. With Polaris you can now query any data source that provides a PowerShell interface to pass it’s information to a dashboard.

https://support.squaredup.com/v3/Walkthroughs/Tiles/HowToUseTheWebAPITile/

 

Concrete examples will follow.

 

Further reading

A while ago I blogged on 4sysops an example of using Polaris. It helps to get a first understanding on how it works.

https://4sysops.com/archives/use-polaris-to-create-a-restful-webservice-in-powershell-for-managing-ad-users/

One thought on “Build REST Service in PowerShell using Polaris”

Leave a Reply