MaxLib.WebServer 4.0.0

dotnet add package MaxLib.WebServer --version 4.0.0
NuGet\Install-Package MaxLib.WebServer -Version 4.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MaxLib.WebServer" Version="4.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MaxLib.WebServer --version 4.0.0
#r "nuget: MaxLib.WebServer, 4.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MaxLib.WebServer as a Cake Addin
#addin nuget:?package=MaxLib.WebServer&version=4.0.0

// Install MaxLib.WebServer as a Cake Tool
#tool nuget:?package=MaxLib.WebServer&version=4.0.0

MaxLib.WebServer

.NET
Core NuGet
Publish License:
MIT Current
Version Top Language

MaxLib.WebServer is a full web server written in C#. To use this webserver you only need to add the .NuGet package to your project, instantiate the server in your code and thats it. No special configuration files or multiple processes.

This web server is build modular. Any modules can be replaced by you and you decide what the server is capable of. The server can fully configured (including exchanging the modules) during runtime - no need to restart everything.

Some of the current features of the web server are:

  • HTTP web server (of course, that's the purpose of the project)
  • HTTPS web server with SSL certificates
  • HTTP and HTTPS web server on the same port. The server detects automatically what the user intends to use.
  • Asynchronous handling of requests. Every part of the pipeline works with awaitable Tasks.
  • REST Api builder. You can directly bind your methods to the handlers.
  • Chunked transport. The server understands chunked data streams and can produce these.
  • Lazy handling of requests. The server allows you to produce the content while you are sending the response. No need to wait.
  • Work with components that belongs to another AppDomain with Marshaling.
  • Deliver contents from your local drive (e.g. HDD)
  • Session keeping. You can identify the user later.
  • ...

Getting Started

This will add MaxLib.WebServer to your project and create a basic server with basic functions.

Installing

Add the MaxLib.WebServer package.

dotnet add package MaxLib.WebServer

Create a simple server

Write somewhere in your code (e.g.) in your Main method of your programm the following snippet:

using MaxLib.WebServer;
using MaxLib.WebServer.Builder; // this using is used later in this tutorial

// ...

using var server = new Server(new WebServerSettings(
    8000, // this will run the server on port 8000
    5000  // set the timout to 5 seconds.
));

// now add some services. You can use your own implementations but here we
// will add a basic set of services from MaxLib.WebServer.Services.
server.InitDefault();

// the server can now be started. A basic set of services is defined so a new
// request will be handled and the user gets a response. Right now its a 
// 404 NOT FOUND but we will add more.
server.Start();

// if you want to stop the server but don't release any of its resources you can do it with:
server.Stop();

Right now you can start the server and open the url http://localhost:8000 in your browser and will get a nice 404 response.

Create own service

Now we will create our own service, that will responds with a beautiful "Hello World" message.

Create a new class MyServices and put this code in it:

using System;
using System.Threading.Tasks;
using MaxLib.WebServer;
using MaxLib.WebServer.Builder;

// every service that uses the included Builder system needs to be derived from Service
public class MyServices : Service
{
    // this method should listen on /hello and return a nice hello
    [Path("/hello")]
    public string Hello()
    {
        return "<html><head><title>Hello World</title></head>" +
            "<body><h1>Hello World!</h1></body></html>";
    }
}

Now you need to add this line to add your service to server:

server.AddWebService(Service.Build<MyServices>()!);

After that you can run your programm and open the page http://localhost:8000/hello. You will see your hello world message.

More information about the new builder system can be found here

Example

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

Lincense

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • StackOverflow for the help
  • Wikipedia, SelfHTML and Mozilla for their documentation
  • PurpleBooth for her README.md template

Last Words

This project was a free time project of mine and I have done it because why not. The source code was a long time a part of MaxLib (a collection of other fun projects and code) but got its own repository for better maintenance.

Some of the documentation inside the code is still in German and other things needs to be optimized.

I have used this for some projects with my friends. It can handle some TB of traffic over a long period without any problems or crashes. I am a little proud of this.

I will further maintain and extend this library if I have new cool features in mind (this was the case for the full WebSocket support and easy Builder System).

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.0 93 2/18/2024
3.6.0 470 5/30/2022
3.5.2 382 5/23/2022
3.5.1 371 5/7/2022
3.5.0 419 5/1/2022
3.4.1 388 3/18/2022
3.4.0 555 2/16/2022
3.3.0 367 2/12/2022
3.2.1 376 2/7/2022
3.2.0 377 2/7/2022
3.1.1 392 2/4/2022
3.1.0 616 1/28/2022
3.0.0 382 11/9/2021
2.8.1 384 10/31/2021
2.8.0 505 8/27/2021
2.7.1 293 8/15/2021
2.7.0 336 3/10/2021
2.6.0 290 2/16/2021
2.5.0 302 2/14/2021
2.4.2 317 2/7/2021
2.4.1 297 2/7/2021
2.4.0 290 2/1/2021
2.3.1 305 1/15/2021
2.3.0 463 1/10/2021
2.2.2 296 1/4/2021
2.2.1 353 1/4/2021
2.2.0 319 1/4/2021
2.1.1 367 1/4/2021
2.1.0 365 12/18/2020
2.0.0 382 12/18/2020
1.0.1 331 12/16/2020
1.0.0 322 12/15/2020