Skip to content
Mark edited this page Mar 5, 2019 · 1 revision

CygniAPI wiki page

Here you can find all the links to other pages:

Simple example

Lets get started adding the using directive: using CygniAPI; on top of your source file.

After that set the configuration of the server to a customized one:

var config = new CygniConfiguration { ListeningPort = 8080, ListeningPath = "localhost" };

Depending on your rights and the system you are running your project, you probably would have to reserve the host and the port for your user to be able to host the server on your machine.

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 user opens page http://localhost:8080/date representing 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 pased to the response body.

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

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

server.Start();

Now when you would try to open http://localhost:8080/date you should see current UTC date and time.

Clone this wiki locally