ModdableWebServer 2.0.0-alpha

This is a prerelease version of ModdableWebServer.
dotnet add package ModdableWebServer --version 2.0.0-alpha
                    
NuGet\Install-Package ModdableWebServer -Version 2.0.0-alpha
                    
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="ModdableWebServer" Version="2.0.0-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ModdableWebServer" Version="2.0.0-alpha" />
                    
Directory.Packages.props
<PackageReference Include="ModdableWebServer" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ModdableWebServer --version 2.0.0-alpha
                    
#r "nuget: ModdableWebServer, 2.0.0-alpha"
                    
#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.
#:package ModdableWebServer@2.0.0-alpha
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ModdableWebServer&version=2.0.0-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=ModdableWebServer&version=2.0.0-alpha&prerelease
                    
Install as a Cake Tool

Moddable Web Server

About

This project is made because I used more than 2 project the NetCoreServer Library and each project is used to make a Server that support more C# DLL to be loaded.

I am really bad at making a Good Documentation. Please help!

Using the Library

Response Creator

Creating response simple.

Make sure you adding like this:
Header
Cookie
Body

//here you create a simple 200 (OK) response.
ResponseCreator response = new();
//adding one Header to it.
response.SetHeader("key","value");
//adding multiple header to it.
response.SetHeaders(
	new Dictionary<string, string>() 
	{
		{ "key", "Value" }
	}
);

//adding content to it.
response.SetBody("Hello World?");

//Getting the HttpResponse.
_ = response.GetResponse();

//we can use the already made creator for start to make a new one.
response.New(404);

If you ever will need, you can use response.SetResponse, but not suggesting it.

Use of HTTPAttribute

[HTTP("Method", "Url")]

In Method can be used any HTTP/S Method.
GET, POST, HEAD, OPTION, DELETE is accepted.

In the Url you can use the full url, or making it as parameter
If you use parameter you can use ?{!args} to parse every arg into the parameters

//url
[HTTP("GET", "/full/url")]

//parameter
[HTTP("GET", "/hey/{parameters}")]

//parameter and normal args
[HTTP("GET", "/hey/{parameters}?user={username}")]

//parameter and args
[HTTP("GET", "/hey/{parameters}?{!args}")]

Make sure your Function must be STATIC and must return a BOOL.

[HTTP("GET", "/test")]
public static bool test(ServerSender sender)
{
	//simple response making
    sender.Response.MakeOkResponse();
    sender.SendResponse();
	//return is if the page exist or not. It will try to send 404 if false.
	return true;
}

Example or Return a false:

[HTTP("GET", "/throw404")]
public static bool throw_404(ServerSender _)
{
	return false;
}

WS(S)

Use of WSAttribute

In the Url you can use the full url, or making it as parameter

Make sure your Function is STATIC, and must a VOID.

 [WS("/ws/{test}")]
 public static void ws(WebSocketStruct webStruct)
 {
	 //bunch of stuff for printing.
     Console.WriteLine(webStruct.IsConnected);
     Console.WriteLine(webStruct.Request.Url);
     Console.WriteLine(webStruct.WSRequest?.buffer);
     Console.WriteLine(webStruct.WSRequest?.offset);
     Console.WriteLine(webStruct.WSRequest?.size);
	 //answering in the websocket.
     webStruct.SendWebSocketText("test");
 }

Making a server.

Here you gonna see how we make a server and using it.

Certificate for Secure server.

Make sure you have a PFX file in a disk, and a password for that pfx file (The PFX file must use a password!)

Using Fields Neccesary:

//add this into the before the classname
using System.Security.Authentication;
using ModdableWebServer.Helper;

You can use any SslProtocol for this, I always use TLS 1.2

//Get Context with Validation
CertHelper.GetContext( SslProtocols.Tls12, "mypfx.pfx", "asecurepassword");

//Get Context with No Validation
CertHelper.GetContextNoValidate( SslProtocols.Tls12, "mypfx.pfx", "asecurepassword");

Creation

You can use any of it to make a sever

var context = CertHelper.GetContext( SslProtocols.Tls12, "mypfx.pfx", "asecurepassword");
var ws_server = new WS_Server("127.0.0.1", 6666);
var wss_server = new WSS_Server(context, "127.0.0.1", 6667);
var http_server = new HTTP_Server("127.0.0.1", 6668);
var https_server = new HTTPS_Server(context, "127.0.0.1", 6669);

Starting and Stopping.

Simply just use Start(), or Stop()

ws_server.Start();
ws_server.Stop();

Adding our created Attributes to the Server

Merging (Will fail if other DLL already contains url/method)

// Loading Entry assembly contained HTTP/HTTPHeader/WS Attribute and merging.
ws_server.HTTPAttributeToMethods.Merge(Assembly.GetEntryAssembly());
// ONLY available for WebSocket servers.
ws_server.WSAttributeToMethods.Merge(Assembly.GetEntryAssembly()); 

Overriding. It will replace already existing ones.

// Loading Entry assembly contained HTTP/WS Attribute and merging.
ws_server.HTTPAttributeToMethods.Override(Assembly.GetEntryAssembly());
ws_server.WSAttributeToMethods.Override(Assembly.GetEntryAssembly());

Assembly Difference

This is so Technical I needed to check like 5 times.

We have 4 Assembly: ModdableWebServer (MWS)
MyServerLib (Lib)
MyServerExtenstion (Extension)
MyServerConsole (Console)

Console starts a Lib.
Lib starts MWS.
Lib starts Extension.

Extenstion Contain a Class: EXT
Lib Contains a Class: LIBC
Console Contains a Class: CONC

GetEntryAssembly = Console
GetCallingAssembly On Extension = Lib
GetCallingAssembly On Lib = Console
GetExecutingAssembly On Lib = Lib
GetExecutingAssembly On Extension = Extension
GetExecutingAssembly On Console = Console
GetAssembly(typeof(EXT)) = Extension
GetAssembly(typeof(LIBC)) = Lib
GetAssembly(typeof(CONC)) = Console

Use the GetAssembly and TypeOf if you dont know what Assembly loaded what!

Product Compatible and additional computed target framework versions.
.NET 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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 (1)

Showing the top 1 popular GitHub repositories that depend on ModdableWebServer:

Repository Stars
SlejmUr/PayCheck3
PayDay 3 Server Emulator Attempt
Version Downloads Last Updated
2.0.0-alpha 438 7/24/2025
1.8.0 101 7/12/2025
1.7.1 361 3/5/2025
1.7.0 227 3/4/2025
1.6.0 149 2/1/2025
1.5.0 304 8/7/2024
1.4.0 210 3/16/2024
1.3.2 223 2/13/2024
1.3.1 176 2/2/2024
1.3.0 156 1/25/2024
1.2.1 231 1/1/2024
1.2.0 172 12/28/2023
1.1.1 382 10/16/2023
1.1.0.1 251 10/14/2023
1.1.0 206 10/14/2023
1.0.0 200 10/13/2023

2.0.0-alpha!