Servers are pretty simple.
You listen and then you reply.
That's Servers 101.
Frameworks often abstract this away.
This can make the basics of servers harder to learn.
To avoid reliance on the framework flavor of the week, it's good to learn how to build a simple server.
This is a collection of simple servers in PowerShell.
Feel free to contribute and add your own.
- DebugServer.ps1
- DualEventServer.ps1
- EventServer.ps1
- MathServer.ps1
- MethodSwitchServer.ps1
- Server101.ps1
- SwitchRegexServer.ps1
You can install Servers101 from the PowerShell Gallery
Install-Module Servers101Once installed, you can import it:
Import-Module Servers101 -PassThruThis module has only one command, Get-Servers101.
It will return all of the sample servers in the module.
Each server will be self-contained in a single script.
To start the server, simply run the script.
To learn about how each server works, read thru each script.
Because each server is contained within a single file, the servers can be streamed to a file
For example, to start a local file server, we can run:
Invoke-RestMethod https://cdn.jsdelivr.net/gh/PoshWeb/Servers101@latest/Servers/Server101.ps1 > ./server.ps1;
./server.ps1For some servers it is also possible to run with Invoke-Expression.
You should never Invoke-Expression code you cannot trust and verify.
To stream a local file server, we can run:
irm https://cdn.jsdelivr.net/gh/PoshWeb/Servers101@latest/Servers/Server101.ps1 | iex