r/PowerShell • • Feb 04 '20

Pode - PowerShell Web Server

I've been meaning to post about this on here for a while, so thought a new release would be a good time!

Pode is a cross-platform pure PowerShell Web Server - even HTTPS. There's also support for template engines in views, and even Azure Functions and AWS Lambda support.

Pode lets you build fully custom REST APIs and Websites, with support for Routing, Middleware, Sessions, CSRF, Authentication, and even Web Sockets.

You can run Pode on Windows or Linux, as a Windows/Linux service, in a Docker container, or even on a Raspberry Pi!

The latest release, v1.5.0, now adds OpenAPI and Swagger/ReDoc support.

You can find Pode on [Github] with a full list of features, and the documentation here.

I know some people frown at the idea of PowerShell as a Web Server, but for DevOps Automation and Dashboards it can be quite a useful tool to have! :)

116 Upvotes

30 comments sorted by

View all comments

3

u/SupremeDictatorPaul Feb 05 '20

Very cool. I wrote a multi threaded web server in PowerShell (PEWebServer) around 2 years ago. I took inspiration from Polaris and PSWebServer, and I’m sad I couldn’t pull some from yours.

Mine was for the very niche case of running in Windows PE. For some reason, http.sys says it’s not licensed for WinPE, so the HttpListener class is not available. I had to use a a raw TCP socket and built my own HTTP parser/generator to recreate the HttpListener class. Because they weren’t needed, I didn’t implement encryption or authentication (and wow would doing TLS have been insane).

In any case, it’s incredible how useful and flexible a web server written in PowerShell can be.

3

u/Badgerati Feb 05 '20

I know what you mean about creating HttpListener from scratch! Because it doesn't support HTTPS outside of Windows I ended up also have to roll my own eventually - likewise for web sockets as well.

Almost pulled my hair out doing it! But managed to throw together a server with socket helpers. It was an experience that's for sure, haha!

3

u/SupremeDictatorPaul Feb 05 '20

I hadn't realized there was so much drama over the HttpListener class out there with pwsh. I assume my code would work in pwsh, but I'm not sure.

I've only done a quick browse through the repo, but it looks like you've done some impressive work. When I get time, I want to look deeper at your Get-PodeServerRequestDetails to compare to my own ConvertFrom-HTTP to see if there are performance gains or fixes to made. Yours is far more succinct, but I was trying to recreate the HttpListener object as much as reasonable because I wasn't sure what parts I would end up needing. (Again, different use cases.)

2

u/Badgerati Feb 05 '20

I was also surprised when I saw they'd deprecated HttpListener.

Your ConvertFrom-HTTP is impressive! Wish I'd come across it when I tried making my own, hah!

I was able to shortcut a lot of what was in HttpListener, but I was using it as a rough guide. A lot of what it does I just didn't need, which helped a fair bit.