官术网_书友最值得收藏!

How to do it...

Going from zero to hello world with Nancy is as simple as following these steps:

  1. Open Visual Studio.
  2. 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.
  3. 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.
  4. 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";
        }
      }
    }
  5. 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.

主站蜘蛛池模板: 湟中县| 泊头市| 长丰县| 中超| 万载县| 蓬溪县| 高要市| 北川| 济阳县| 红原县| 新乐市| 泰安市| 江孜县| 景宁| 武邑县| 馆陶县| 赣榆县| 宁都县| 营山县| 泸西县| 长武县| 西乌珠穆沁旗| 峨眉山市| 玛曲县| 宜宾县| 广汉市| 黄冈市| 衢州市| 吕梁市| 呼图壁县| 武定县| 西峡县| 遵化市| 板桥市| 昌宁县| 南通市| 阳高县| 宜昌市| 军事| 开封市| 弥渡县|