- Instant Nancy Web Development
- Christian Horsdal
- 242字
- 2021-08-04 09:59:25
How to do it...
Going from zero to hello world with Nancy is as simple as following these steps:
- Open Visual Studio.
- Create a new empty ASP.NET project by navigating to File | New Project... and selecting the ASP.NET Empty Web Application template under Visual C# | Web. Let's call the project
HelloNancy
. - Open Package Manager Console. At the prompt, type the following line of code:
PM> Install-Package Nancy.Hosting.Aspnet
The previous line of code will produce an output similar to this:
Attempting to resolve dependency 'Nancy (≥ 0.17.1)'. Installing 'Nancy 0.17.1'. Successfully installed 'Nancy 0.17.1'. Installing 'Nancy.Hosting.Aspnet 0.17.1'. Successfully installed 'Nancy.Hosting.Aspnet 0.17.1'. Adding 'Nancy 0.17.1' to HelloNancy. Successfully added 'Nancy 0.17.1' to HelloNancy. Adding 'Nancy.Hosting.Aspnet 0.17.1' to HelloNancy. Successfully added 'Nancy.Hosting.Aspnet 0.17.1' to HelloNancy.
- Add a new C# file at the root of the project. Call it
HelloModule
and put the following code in it:namespace HelloNancy { using Nancy; public class HelloModule : NancyModule { public HelloModule() { Get["/"] = _ => "Hello Nancy World"; } } }
- Press F5 and marvel at the fact that you've just created your first Nancy application. When you run this application, you should see something rather close to this:
Tip
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.
推薦閱讀
- JBoss Weld CDI for Java Platform
- Git Version Control Cookbook
- Visual Basic程序設(shè)計(jì)教程
- 3D少兒游戲編程(原書第2版)
- Visual Basic程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)(第二版)
- 第一行代碼 C語(yǔ)言(視頻講解版)
- OpenResty完全開發(fā)指南:構(gòu)建百萬級(jí)別并發(fā)的Web應(yīng)用
- 一本書講透Java線程:原理與實(shí)踐
- Python3.5從零開始學(xué)
- Learning Hadoop 2
- Java Web開發(fā)實(shí)例大全(基礎(chǔ)卷) (軟件工程師開發(fā)大系)
- 算法圖解
- 計(jì)算機(jī)應(yīng)用基礎(chǔ)案例教程(第二版)
- Learning RSLogix 5000 Programming
- SQL Server 2008數(shù)據(jù)庫(kù)應(yīng)用技術(shù)(第2版)