Skip to content
Collection of utility methods used in the Butterfly Server
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Butterfly.Util Butterfly Logo

Collection of utility methods used in the Butterfly Server

Install from Nuget

Name Package Install
Butterfly.Web nuget nuget install Butterfly.Web
Butterfly.Web.EmbedIO nuget nuget install Butterfly.Web.EmbedIO
Butterfly.Web.RedHttpServer nuget nuget install Butterfly.Web.RedHttpServer

Install from Source Code

git clone

Working with Dictionaries

Since Dictionary<string, object> is used so extensively, you'll likely find it useful to declare an alias with your other using statements...

using Dict = System.Collections.Generic.Dictionary<string, object>;

Butterfly.Core.Util contains a GetAs extension method for Dict that makes it easier to convert values...

Here are a few common scenarios related to database records...

// Retrieve from the todo table using the primary key value
Dict row = await database.SelectRowAsync("todo", "123");

// Retrieve as string
var id = row.GetAs("id", "");

// Retrieve as integer
var count = row.GetAs("count", -1);

// Retrieve as float
var amount = row.GetAs("id", 0.0f);

// Retrieve as DateTime instance (auto converts UNIX timestamp)
var createdAt = row.GetAs("created_at", DateTime.MinValue);

Here are a couple common scenarios related to the Web API...

webApi.OnPost("/api/todo/insert", async (req, res) => {
    var todo = await req.ParseAsJsonAsync<Dict>();

    // Retrieve as array
    var tags = todo.GetAs<string[]>("tags", null);

    // Retrieve as dictionary
    var options = todo.GetAs<Dict>("options", null);


If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.


The code is licensed under the Mozilla Public License 2.0.

You can’t perform that action at this time.