GenHTTP is a lightweight web server written in pure C# with a strong focus on developer experience. The main purpose of this project is to quickly create web services written in .NET 8 / 9, allowing developers to concentrate on the functionality rather than on messing around with configuration files or complex concepts.
- Setup new webservices in a couple of minutes using project templates
- Supports current standards such as Open API, Websockets, Server Sent Events or JWT authentication
- Embed web services into a new or already existing console, service, WPF, WinForms, WinUI, MAUI or Uno application
- Projects are fully described in code - no configuration files needed, no magical behavior you need to learn
- Supports Kestrel as an underlying HTTP engine (enables HTTP/2 and HTTP/3 via QUIC)
- Optimized out of the box, small memory and storage footprint
- Grade A+ security level according to SSL Labs
This section shows how to create a new project from scratch using project templates and how to extend your existing application by embedding the GenHTTP engine.
Note
This is a brief overview to get you running. You might want to have a look at the tutorials for detailed step-by-step guides.
Project templates can be used to create apps for typical use cases with little effort. After installing
the .NET SDK and the templates via dotnet new -i GenHTTP.Templates
in
the terminal, the templates are available via the console or directly in Visual Studio:
To create a project by using the terminal, create a new folder for your app and use one of the following commands:
Template | Command | Documentation |
---|---|---|
REST Webservice | dotnet new genhttp-webservice |
Webservices |
REST Webservice (single file) | dotnet new genhttp-webservice-minimal |
Functional Handlers |
REST Webservice (controllers) | dotnet new genhttp-webservice-controllers |
Controllers |
Websocket | dotnet new genhttp-websocket |
Websockets |
Website (Static HTML) | dotnet new genhttp-website-static |
Statics Websites |
Single Page Application (SPA) | dotnet new genhttp-spa |
Single Page Applications (SPA) |
After the project has been created, you can run it via dotnet run
and access the server via http://localhost:8080.
If you would like to extend an existing .NET application, just add a nuget reference to the GenHTTP.Core
nuget package. You can then spawn a new server instance with just a few lines of code:
var content = Content.From(Resource.FromString("Hello World!"));
var host = await Host.Create()
.Handler(content)
.Defaults()
.StartAsync(); // or .RunAsync() to block until the application is shut down
When you run this sample it can be accessed in the browser via http://localhost:8080.
The documentation provides a step-by-step starting guide as well as additional information on how to implement webservices, minimal webservices, controller-based webservices, static websites, or single page applications and how to host your application via Docker.
If you encounter issues implementing your application, feel free to join our Discord community to get help.
To build the server from source, clone this repository and run the playground project launcher for .NET 9:
git clone https://github.com/Kaliumhexacyanoferrat/GenHTTP.git
cd ./GenHTTP/Playground
dotnet run
This will build the playground project launcher with all the server dependencies and launch the server process on port 8080. You can access the playground in the browser via http://localhost:8080.
Writing a general purpose web application server is a tremendous task, so any contribution is very welcome. Besides extending the server core, you might want to
- Leave a star on GitHub
- Extend the content capabilities of the server (e.g. by adding a new serialization format or rendering engine)
- Refine our project templates
- Perform code reviews
- Analyze the performance or security of the server
- Clarfify and extend our tests
- Improve the documentation on the website or in code
If you would like to contribute, please also have a look at the contribution guidelines and the good first issues.
The web server was originally developed in 2008 to run on a netbook with an Intel Atom processor. Both IIS and Apache failed to render dynamic pages on such a slow CPU back then. The original project description can still be found on archive.org. In 2019, the source code has been moved to GitHub with the goal to rework the project to be able to run dockerized web applications written in C#. In 2024 the focus has shifted towards API development, dropping support for generating graphical web applications.
- Related to GenHTTP: Templates | Website
- Reference projects: GenHTTP Gateway | MockH
- Similar projects: EmbedIO | NetCoreServer | Watson Webserver | SimpleW
- Powered by .NET
- Less allocations thanks to PooledAwait
- Modules implemented with NSwag (Open API), Fleck (WebSockets)