Home

Awesome

Nina

Nina is a web microframework for the .Net platform, inspired by Sinatra. It includes several aspects that go futher beyond Sinatra, such as an abstract, pluggable, and extensible infrastructure.

An important note is that Nina is feature complete. Meaning that unlike open source projects that forge themselves online, it was brewed for a while before opening up to public. Its API stable and well thought out, Nina will not be a moving target for you, and you can count on it.

Nina discussion group: http://groups.google.com/group/nina-dev

Features

To put some code into words:

Get("book.xml", (m, c) =>
{
    Filters.ETag("8");
    return Xml(new Model());
});

Get("etagged/crc/book.xml", (m, c) =>
{
    return Xml(new Model()).ETagged();
});

Get("etagged/md5/book.xml", (m, c) =>
{
    return Xml(new Model()).ETagged(Digest.MD5);
});

Get("etagged/text", (m, c) =>
{
    return Text("thanks").ETagged();     
});
    
Get("book/{name}", (m, c) =>
{
    return View("views/foo", new Model()).Created(c.Request.Url.ToString()).ETagged();
});        

RESTful

Nina keeps REST easy, as it was planned to be. Supporting all verbs, through native

Get("guest/{name}", (m,c) => Text("Hello, " + m["name"]));
Post("/", (m,c) => View("views/blog", new Blog()));
Put("/{id}/comments", (m,c) => Json(GetBlogWithComments()));
Delete("/files/{id}", (m,c) => File(CONFIRMATION));

Friendly

Inspired by Sinatra, Nina has a compact and friendly DSL that you'll like from the start.

Post("/", (m,c)=>
{
  var url = Urls.Save(c.Request.Form["url"]);
  return Text(string.Format(@"<html><body>Your url: 
            <a href='{0}'>{0}</a></body></html>", c.Request.Url +url));
});

Nina doesn't try to be everything. It does try to give you scenario-based programming experience with performance to boot: ETagging, cache-control, JSON and XML serialization, growing number of view engines including <a href="http://code.google.com/p/nhaml/">NHaml</a>, <a href="http://ndjango.org/">NDjango</a>, <a href="http://sparkviewengine.com/">Spark</a> and more.

Nina lets you worry about your own code by giving you less decisions to make. In order to be more friendly, sometimes, there is (and should be) only one way to do it.

High Performance

Under the hood, Nina is a highly optimized microframework with comprehensive features and a neat DSL.

To put it into numbers, here is the typical string rendering benchmark.

Nina/.NET2.0, IIS 
Requests per second:    2385.19 [#/sec] (mean)

Sinatra/Ruby1.8.7, Thin 
Requests per second:    588.33 [#/sec] (mean)

Although benchmark comparisons are evil, biased, and so forth, it does give a good feel about running a lightweight framework on windows and IIS.

Get Started

A tutorial is in progress. As well as blog-series explaining Nina's underpinnings (no pun intended). For now there are several examples for using Nina:

The TinyUrl Example

Here is a self-contained complete Nina application, for a tiny url website. Nice, isn't it? Check out Nina.Demo.Tinyurl to play with it live.

//TinyUrl.cs
public class TinyUrl : Nina.Application
{
    private static readonly Urls Urls = new Urls();
    public TinyUrl()
    {
        Get("/", (m,c) => Text("<html><body>Tiny url!<form method='post'><input type='text' name='url'/><input type='submit' value='tiny!'/></form></body></html>"));
        
        Post("/", (m,c)=>
        {
            var url = Urls.Save(c.Request.Form["url"]);
            return Text(string.Format("<html><body>Your url: <a href='{0}'>{0}</a></body></html>", c.Request.Url +url));
        });

        Get("/{tinyurl}", (m, c) => Redirect(Urls.Get(m["tinyurl"])) );
    }
}

public class Urls
{
    private readonly List<string> _urls = new List<string>();

    public string Save(string s)
    {
        _urls.Add(s);
        return (_urls.Count-1).ToString();
    }
    public string Get(string u)
    {
        var i = int.Parse(u);
        return _urls[i];
    }
}

Contributors

Dotan Nahum (jodnot)
Matt Burton (mattburton)

Future plans

Currently Nina is feature complete. It should cover most of the scenarios building RESTful web applications. However, I do have several more extras on the way which are always

Contribute

Nina is an open-source project. Therefore you are free to help improving it. There are several ways of contributing to Nina's development:

License

This code is free software; you can redistribute it and/or modify it under the terms of the Apache License. See LICENSE.txt.

Copyright

Copyright (c) 2010, Dotan Nahum dotan@paracode.com