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

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.

主站蜘蛛池模板: 连云港市| 九寨沟县| 凯里市| 广水市| 确山县| 阿拉善盟| 清镇市| 九台市| 景德镇市| 斗六市| 攀枝花市| 宝兴县| 阿坝| 莲花县| 比如县| 专栏| 长治市| 延吉市| 公安县| 蒲城县| 花莲县| 五指山市| 万山特区| 闻喜县| 镇原县| 白沙| 吐鲁番市| 侯马市| 彝良县| 荣成市| 诸暨市| 拜城县| 神木县| 三明市| 宁河县| 明水县| 碌曲县| 金山区| 柳河县| 景泰县| 长葛市|