The following article shows how to set up an artless HTTP server using .NET Core. I’ve already spoken about .NET Core and ASP.NET Core in the following posts:
.NET Core 2.1 highlights: standing on the shoulders of giants
Developing APIs using Actor model in ASP.NET Core
Fast growing architectures with serverless and .NET Core
.NET Core is the brand new framework developed by Microsoft and the community. It follows an approach similar to NPM, furthermore, it is possible to install 3rd party global tools implemented by the community. In practice, the .NET Core Global Tools are NuGet packages that contain a simple console application and they are runnable on your local machine. The following example shows how to use .NET Global tools to run an artless HTTP server.
Nate McMaster, a member of the ASP.NET Core team, has released a simple tool that provides an easy way to run an HTTP server on your machine. The only requirement is .NET Core 2.1 or newer installed on your development machine.
Run the HTTP Server
We can run the following command to install the tool:
dotnet tool install --global dotnet-serve
After that, it is possible to execute the command to run the HTTP server:
dotnet serve -o -S
-o argument triggers the default browser, and the
-S argument provides the HTTPS connection.
Also, the console application also accepts the following arguments:
The command runs the server in the current path; if the folder contains an index.html file or, more in general, an file which can be served, it is returned by default. Otherwise, it will show the list of folders and data present in the path.
The following tool provides a quick and easy way to set up an HTTP server and provide content quickly. It also shows the power of .NET Core its portability. Since we are running it on .NET Core, it is cross-platform and runnable on every OS.
For more information, you can have a look at the following repository:
Cover image – Winter lights Canary Wharf