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