Skip to content

Getting started building a simple Nancy API

What is Nancy?

What? Other than it being totally AWESOME?! 

Nancy is a framework for creating web applications. It makes sure to implement the super-duper-happy-path, which means it requires very little effort to get a website up and running.

Here I will give a basic overview of how to build a Nancy API.

 

Why choose Nancy?

The thing I love about using Nancy, is that I can build my web app in Visual Studio in Windows, but I am also able to run it in Linux! Or even run it in a Docker container. I am looking forward to Visual Studio being available for OSX, where everything should still work! 🙂

It is also really easy to use. There are so many Nuget packages out there that can add additional functionality to your Nancy app.

 

How is a Nancy API project structured?

A Nancy web application (in a nutshell) is a collection of modules. These modules define the routes for your application, and contain all the code you want to execute.

I commonly use Owin to host my Nancy app, which needs to Microsoft.Owin.Host.SystemWeb and create a Startup class to initialize the application.

  • Models
    • This contains the models you want to return from the API
  • Modules
    • The guts of the application
    • These modules contain the routes for your web app
  • Bootstrapper.cs
    • Manually register dependencies
    • Add additional features to you Nancy app
  • Startup.cs
    • Add Nancy to the Owin pipeline

 

The Startup class

A simple Nancy module

 

Next steps

What I have just talked about is very basic, but it is definitely enough to get you started. In my next posts I will show you how to build a simple todo application using Nancy (seems to be the standard tutorial app)This will include how to do testing using the Nancy.Testing package! Then I shall also create a post on how to do continuous integration using GitLab CI 🙂

Published in.NETC#C#

Be First to Comment

Leave a Reply

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