background preloader

Nancy

Facebook Twitter

C# - .NET Core Nancy sample application with static files as a frontend. Use NancyFx in ASP.NET Core. NancyFx is a lightweight, low-ceremony, framework for building HTTP based services on .NET and Mono. The goal of the framework is to stay out of the way as much as possible and provide a super-duper-happy-path to all interactions. Advantage of NancyFx is, it prefers conventions over configuration and supports DELETE, GET, HEAD, OPTIONS, POST, PUT and PATCH requests and provides a simple and elegant way to return response with just a couple of keystrokes.

In this post, let’s find out how to use NancyFx in ASP.NET Core. Before we move to using NancyFx with ASP.NET, here is some advantage of NancyFx. No configuration required. I recommend you to read the post Why use NancyFX?. Let’s see how to use it in the ASP.NET Core application. Microsoft.AspNetCore.Owin: “1.0.0”Nancy: “2.0.0-barneyrubble” Now we need to make sure the Nancy handles the request, instead of the ASP.NET runtime. Now we need to create a Module that will handle the request. That’s it. Thank you for reading. Related In "ASP.NET" Using NancyFx in ASP.NET Core - dotnetthoughts. Posted by Anuraj on Saturday, August 20, 2016 C# asp.net core NancyFx This post is about using NancyFx in ASP.NET Core. NancyFx is lightweight, low-ceremony, framework for building HTTP based services on .Net and Mono. The goal of the framework is to stay out of the way as much as possible and provide a super-duper-happy-path to all interactions.

This is an empty asp.net core application, in which you need to add Nancy references. The “Microsoft.AspNetCore.Owin” package is important, which will help you to use “UseOwin” method. Public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory){ loggerFactory.AddConsole(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseOwin(x => x.UseNancy());} And you need to create a Nancy module to handle the requests. This above code will handle requests to the / and will return “Hello World” as plain text. Here is the response using POSTMAN And here is the code for handling a POST request.

ASP.NET Core Series: NancyFX - CodeOpinion. Last week I decided to start migrating one of my existing ASP.NET application that uses NancyFX over to ASP.NET Core. The process is actually pretty straight forward if you are familiar with OWIN. OWIN defines a standard interface between .NET web servers and web applications.

The goal of the OWIN interface is to decouple server and application, encourage the development of simple modules for .NET web development, and, by being an open standard, stimulate the open source ecosystem of .NET web development tools. To clarify and reword slightly, OWIN is a open source specification that is not defined by Microsoft and is not an actual implementation. ASP.NET Core supports OWIN and defines middleware to be used in a request pipeline with the Microsoft.AspNet.Owin package.

ASP.NET Core NancyFX Demo All of the source code for this demo is available on GitHub. The first thing we are going to do for this demo is add the appropriate nuget packages. For the demo, I’ve created a simple Nancy Module.