Tuesday, November 12, 2013

Create First Web API Application

For Creating Web Api first check you have MVC 4  version installed on your machine.

First select new Porject and select MVC4WebAppliction.

After thet select Web API under next wizard. after creation this will look like below image


For creating API we need to workin only one controller file i.e. ValuesController. I have created single get method for learning puspose First Create Customer Class file under model and refrence to on your controller file



After Implementation of Get Methods you need to execute/test this page, you will found API URi like this...

http://localhost:56880/api/Values

After success full creation of Web APi now its time to integrate this on your application.

For demo purpose i have created a page in a same project you can implement this on any other sites also.

In my case for Accessing the created API  need to create Controller APITestController and View for viewing purpose just like below image



once you created the view page now you need to write some code for accessing the API, for example i am writing here in jQuery like below image

No comments:

Post a Comment