ASP. NET core development-using the Nancy framework

Source: Internet
Author: User

about Nancy

Nancy is a lightweight, stand-alone framework, and here are some of the official website introductions:

    • Nancy is a lightweight for building HTTP-based WEB services, based on the. NET and Mono platforms, the goal of the framework is to keep as many ways as possible and provide a super-duper-happy-path of all interactions.
    • Nancy is designed to handle,,,, DELETE GET HEAD OPTIONS POST PUT 和 PATCH etc. request methods and provide a simple and elegant DSL to return the response. Give you more time to focus on your code and programs.

Official address: http://nancyfx.org github:https://github.com/nancyfx/nancy

Nancy released a v2.0.0-barneyrubble version in the previous two days , supporting ASP. NET Core 1.0.

Learn how to use the Nancy framework in ASP.

create an ASP. NET Core Nancy Project

Host uses ASP. NET Core Host Kestrel

Start by creating a new ASP. NET Core application and choose the empty template next.

Below to add a reference.

First add Microsoft.AspNetCore.Owin

Install-package Microsoft.AspNetCore.Owin

Then add Nancy

Install-package Nancy-pre

Once added, we can write code.

Add the Nancy.owin reference in Startup.cs, and include the following code in the Configure method:

        public void Configure (Iapplicationbuilder app, Ihostingenvironment env, iloggerfactory loggerfactory)        {            Loggerfactory.addconsole ();            if (env. Isdevelopment ())            {                app. Usedeveloperexceptionpage ();            }            App. Useowin (x = x.usenancy ());        }

Then we add the module, which is understood to be Nancy's Controller.

Here we add a homemodule, we add a class HomeModule.cs, and then we inherit nancymodule.

    public class Homemodule:nancymodule    {public        homemodule ()        {            Get ("/", r = = "Nancy running on ASP. NET Core Linezero ");            Get ("/{name}", r = "Simple routing template, routing parameters:" +r.name);            Get ("/404", r = = Httpstatuscode.notfound);}    }

Then run the program, where we use Kestrel to run.

http://localhost:5000

Http://localhost:5000/linezero

http://localhost:5000/404

This is Nancy's own 404, and we can handle it ourselves.

This article focuses on the use of Nancy in ASP., more Nancy's introduction and use, can refer to some of my previous articles, Nancy is a very light-weight framework.

If you think this article is helpful to you, please click " recommend ", thank you.

ASP. NET core development-using the Nancy framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.