{"id":13525,"date":"2017-10-16T06:34:53","date_gmt":"2017-10-16T14:34:53","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/?p=13525"},"modified":"2019-03-05T16:36:36","modified_gmt":"2019-03-06T00:36:36","slug":"polaris-simple-microservices-using-only-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/polaris-simple-microservices-using-only-powershell\/","title":{"rendered":"Polaris &#8211; simple Microservices using only PowerShell"},"content":{"rendered":"<div class=\"markdown-body\">\n<h2>Polaris &#8211; Simple Microservices using only PowerShell<\/h2>\n<p><a href=\"https:\/\/github.com\/powershell\/polaris\">Polaris<\/a> is a cross-platform, minimalist web framework for PowerShell Core 6. With 6 lines of code, you have your very own webserver running and ready to accept requests &#8211; all within PowerShell:<\/p>\n<div class=\"highlight highlight-source-powershell\">\n<pre class=\"lang:default decode:true \">New-GetRoute -Path \"\/json\" -ScriptBlock {\r\n\r\n    $json = @{ Hello = \"World\"; TestingTesting = @(1,2,3); }\r\n\r\n    $response.Json(($json | ConvertTo-Json));\r\n}\r\n\r\nStart-Polaris<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n<pre><code>PS \/&gt; Invoke-RestMethod http:\/\/localhost:8080\/json\r\n\r\nHello TestingTesting\r\n----- --------------\r\nWorld {1, 2, 3}\r\n<\/code><\/pre>\n<h3>Disclaimer<\/h3>\n<p>We open sourced this as an experiment. It&#8217;s not an officially supported Microsoft library and there is no plan yet to do so. However, we are listening to the community to determine if this work is important enough to continue investing in.<\/p>\n<h2>Why we made Polaris<\/h2>\n<p>PowerShell is evolving and we want to experiment with other use cases for PowerShell. With .NET Standard 2.0 out, we were able to get our hands on the .NET HttpListener class originally from the .NET Framework. With it comes a solution that works anywhere that PowerShell does.<\/p>\n<p>We also wanted to give those that are really familiar with PowerShell a way to run their own webservers to allow for a language-agnostic way to run PowerShell scripts thanks to HTTP. Imagine a mobile app triggering remote PowerShell scripts all through HTTP. Or hosting a static site and interacting with an external API all using PowerShell for server code.<\/p>\n<p>We&#8217;re excited to see all the use cases emerge and receive feedback from PowerShell&#8217;s already incredible community.<\/p>\n<h2>Roadmap<\/h2>\n<p>We have a few paths we are interested in taking. We hope the community helps direct us.<\/p>\n<ul>\n<li>Expanding on the current implementation using HttpListener to deliver features you&#8217;d expect from projects ASP.NET or Express.js (route parameters, query parameters, middleware etc)<\/li>\n<li>Investigating the use of <a href=\"https:\/\/github.com\/aspnet\/KestrelHttpServer\">Kestrel<\/a>\/<a href=\"https:\/\/github.com\/aspnet\/routing\">ASP.NET Routing<\/a> instead of HttpListener<\/li>\n<li>Support for Windows PowerShell (5.x and lower)<\/li>\n<li>Creating a routing domain-specific language (DSL) for isolating and running script blocks as routes. Drawing inspiration from <a href=\"https:\/\/github.com\/pester\/Pester\/\">Pester<\/a>.<\/li>\n<\/ul>\n<p>We&#8217;re <a href=\"https:\/\/github.com\/powershell\/polaris\">open-sourcing<\/a> this really early on so that we can receive feedback from you. To get started with Polaris, hop on over to the project&#8217;s <a href=\"https:\/\/github.com\/powershell\/polaris\">GitHub<\/a>. We&#8217;re excited to hear what you have to say.<\/p>\n<p>Tyler Leonhardt\nSoftware Engineer\nPowerShell Community and Tools<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Polaris &#8211; Simple Microservices using only PowerShell Polaris is a cross-platform, minimalist web framework for PowerShell Core 6. With 6 lines of code, you have your very own webserver running and ready to accept requests &#8211; all within PowerShell: New-GetRoute -Path &#8220;\/json&#8221; -ScriptBlock { $json = @{ Hello = &#8220;World&#8221;; TestingTesting = @(1,2,3); } $response.Json(($json [&hellip;]<\/p>\n","protected":false},"author":622,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13525","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>Polaris &#8211; Simple Microservices using only PowerShell Polaris is a cross-platform, minimalist web framework for PowerShell Core 6. With 6 lines of code, you have your very own webserver running and ready to accept requests &#8211; all within PowerShell: New-GetRoute -Path &#8220;\/json&#8221; -ScriptBlock { $json = @{ Hello = &#8220;World&#8221;; TestingTesting = @(1,2,3); } $response.Json(($json [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/13525","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/622"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=13525"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/13525\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=13525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=13525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=13525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}