November 20, 2016

Hands On with Nancy REST API - Day 1

Back with the Hands on for Nancy based project as I have promised in the previous post.

Pre-requisites before we jump into hands on session:
1. Visual Studio of any version preferbale to be on 2013 and later
2. Knowledge of C#, MVC(basics)

Thats all and we are ready to go......
Open the Visual Studio, Here I am going with VS2013

  1. Create an ASP.Net empty Web site as shown below:
  2. My Project Name for empty website is MyFirstNancyProject, Right click the project and select Manage Nuget Package and install Nancy
  3. Create a class and here I'm naming my created class as MyNancyClass

4. Import Nancy namespace and inherit the NancyModule to the MyNancyClass
5. Now, time to have some logic inside MyNancyClass constructor
6. Now, as I mentioned in my previous posts about nancy there is super duper happy path, that mean the routing can't be as easy as nancy does.
7. It is time to be SDHP so, I'm creating a HTTP get request followed by routing parameter "/SDHP" as shown below
8. To get it running, we need to install the Nancy's hosting file i.e, Nancy.Hosting.Aspnet from Nuget Package

You are good to go now. Just rebuild the app and run....
Oops.. Did you get the same page when you had run the Site?
Ha ha ha... You forgot to mention the path we had configured for Get request and that was "/SDHP", now try it..
Woo.. here it is.. Now, try new things considering the things we have learned now. I'm sure you will come across a CORS related error going ahead with some UI content.... Next session will be on allowing CORS in nancy API. I will see you soon ;)


Share:

0 comments :

Post a Comment

About Me

My Photo
Innovations and Passion are always been a part of my life. I do things only if I am passionate about it.

Popular Posts

Recent Posts

Total Pageviews