SharpHttpServer 1.0.0

dotnet add package SharpHttpServer --version 1.0.0
NuGet\Install-Package SharpHttpServer -Version 1.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="SharpHttpServer" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SharpHttpServer --version 1.0.0
#r "nuget: SharpHttpServer, 1.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 SharpHttpServer as a Cake Addin
#addin nuget:?package=SharpHttpServer&version=1.0.0

// Install SharpHttpServer as a Cake Tool
#tool nuget:?package=SharpHttpServer&version=1.0.0

SharpHttpServer Library

SharpHttpServer is a lightweight C# Library written by Berka Ayowa that helps you create a standalone HTTP server for your console or windows apps

Latest version 1.0.0

To use the library, just add the SharpHttpServer.dll reference to your c# console or windows project, they are located under the Library folder

##We recommend installing the latest library version 1.0.0 from Nuget, searching SharpHttpServer from NuGet, and installing. Nuget Link https://www.nuget.org/packages/SharpHttpServer

File name: Program.cs

using SharpHttpServer.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("########################################");
            Console.WriteLine("##### Welocme to this console app ######");
            Console.WriteLine("########################################");
            Console.WriteLine("#    This console app has Http Server  #");
            Console.WriteLine("########################################");


            //Set up Log envent
            SharpHttp.Server.OnEvent += Log;

            //Setup & run the Server 
            SharpHttp.Server.Run("http://localhost:8091/", typeof(Program))
            //Only call the function AlwaysOn() if this library is being used in a console app project'
            .AlwaysOn();
        }

        //This is a basic log function 
        //We are just writing logs on the console
        static void Log(SharpHttpLogSource source, SharpHttpLogType logType, object obj)
        {
            //Console.Clear();
            Console.WriteLine(DateTime.Now.ToString() + "-" + obj.ToString());
            
        }
    }
}

Example of a controller class & methods

File name: App.cs

using SharpHttpServer.Attribute;
using SharpHttpServer.Controller;
using SharpHttpServer.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    public class App : SharpHttpServerController 
    {
        //Method Get
        //http://localhost:8091/app/help
        public SharpHttpServerResult Help()
        {
            //returns text/string 
            return Text("In app->help function...");
        }

        //Method Get
        //http://localhost:8091/app/version
        public SharpHttpServerResult Version()
        {
            //retunrs json
            return Json("{\"version\":\"1.0.0\"}");
        }

        //Method Get
        //http://localhost:8091/app/configuration
        public SharpHttpServerResult Configuration()
        {
            //retunrs XML
            return XML("<Config><Version>1.0.0</Version><DateTime>"+DateTime.Now.ToString()+"</DateTime></Config>");
        }

        //This function will only be available on post request
        //Method Post
        //http://localhost:8091/app/command
        [RouteSharpHttp(SharpHttpMethod.POST)]
        public SharpHttpServerResult Command()
        {
            return Text("In app->Command function...");
        }
    }
}


Events
Name Description Example
OnEvent This event for logging pursises SharpHttp.Server.OnEvent += Log;
Action
Name Description Example
Run This action creates & starts running the HTTP server SharpHttp.Server.Run("http://localhost:8091/", typeof(Program));
AlwaysOn This action is used to keep the HTTP server alive in the console app SharpHttp.Server.Run("http://localhost:8091/", typeof(Program)).AlwaysOn();

Sample project can be found in Example folder from the library GitHub repo

Click here to donate for supporting us to keep improving this library

Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

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
1.0.0 187 11/3/2022