CygniAPI – simple .NET web server

A long while ago, I was working on a small project for my own needs – CygniAPI, that would give you access to a simple web server, that takes almost nothing to set up and get running in your application, that can process events quickly in the API like style.

This project was later named CygniAPI and distributed through the GitHub page for everyone for free. As this package is very simple, you can easily and quickly install it with the built-in packet manager and get started with minimal documentation available.

This project is open for contributions, soon I am planning to give more information and wiki on the GitHub page.

You can find CygniAPI project by this link here.

I am posting a very short wiki here, just to show you how easy it is to use.

First, you would be able to install this package via the package manager command:

Install-Package CygniAPI

Then you need to create the instance of a server and configure it with your own configuration example of which can be found at the beginning of this file.

// Create the instance of the server with a predefined custom configuration
var server = new CygniAPI.CygniApiServer(config);

Now we can register your first callback function, let us choose it to display current DateTime in UTC format:

// This method adds a callback function replying to request type **GET**
server.Get("/date", (i, o) =>
{
    o.Append(DateTime.UtcNow);
});

The "/date" means that this callback would be invoked when a user opens the page http://localhost:8080/daterepresenting the substring after the host and port in the URL.

In (i, o) syntax, the i stands for string input that is read from the request body, and the o is the output StringBuilder that is passed to the response body.

Everything that happens in the function is called during the request and anything appended to the oas output would be displayed to the user. In the current example, we would receive the string of the current date and time.

Now, to make it work we would have to start the server using the command:

server.Start();

That’s it. Now you can run your application and test the endpoints. This is a very minimal setup but you can do a lot of useful work quickly and easily. Also, you can modify this project for your own needs as it is completely simple and open source.

On the repository page, there is an Example application as well as written Unit tests. And the library itself contains just 8 files with actual code!

Don’t forget to give credits 🙂

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.