Skip to content

.net8 DLL with simple HTTP-Server running in the background in a separate thread

License

Notifications You must be signed in to change notification settings

PonyvilleDeveloper/Webtech

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Webtech

.net8 DLL with simple HTTP-Server running in the background in a separate thread

Usage

using Webtech;

namespace Foo {
    class Program {
        public static void Main() {
            var api = new REST_API($"{ApiImpl.WorkDir}apiconfig.json", typeof(ApiImpl)); //Available on 127.0.0.1:8080
            Server? backend = new(api);
            backend.Work = true;

            ApiImpl.logger.Info("MAIN", "Server started...");
            Console.ReadKey();
        }
    }
}

or

using Webtech;

namespace Foo {
    class Program {
        public static void Main() {
            var api = new REST_API($"{ApiImpl.WorkDir}apiconfig.json", typeof(ApiImpl));
            Server? backend = new(api, new IPEndPoint(new IPAdress(new byte[] {127, 0, 0, 1}), 8080));
            backend.Work = true;

            ApiImpl.logger.Info("MAIN", "Server started...");
            Console.ReadKey();
        }
    }
}

API config json example

[
    {
        "Name": "Resource",
        "Url": "resources/\\w+/\\w+\\.\\w+",
        "AuthRequired": false,
        "Method": "GET"
    },
    {
        "Name": "TechInfo",
        "Url": "tech",
        "AuthRequired": true,
        "Method": "GET"
    },
    {
        "Name": "Page",
        "Url": "\\w+",
        "AuthRequired": false,
        "Method": "GET"
    },
    {
        "Name": "Auth",
        "Url": "auth",
        "AuthRequired": false,
        "Method": "POST"
    }
]