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.
In terms of features:
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));
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 NHaml, NDjango, Spark 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.
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.
Requests per second: 2385.19 [#/sec] (mean)<br/>
Time per request: 0.544 [ms] (mean)
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:
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]; } }
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 welcome
Nina is an open-source project. Therefore you are free to help improving it. There are several ways of contributing to Nina’s development:
This code is free software; you can redistribute it and/or modify it under the terms of the Apache License. See LICENSE.txt.
Copyright (c) 2010, Dotan Nahum dotan@paracode.com