Creating Web-Api
Hi,
Everyone here i am again , now I am gonna discuss about the web-api
. Web-api is the next level service preferred by everyone . The
advantages that using web-api are, this is HTTP service ,can be
consumed by many clients like Mobiles,tabs,browsers etc..
These
days , Most of the peoples using smart phones and they usually use
apps than browsers in their mobile. So the website and app should work synchronized . Most of the famous websites provide their apis
. So creating your own api is not a bad thing right? we could learn how to create your own Web-api using
Visual studio-2013
Actually
it is very easy lets check it out , how to create a new Web-api
Creating
the web-api project
File --> New --> Project and select web under visual C#
Select WebApi
Click ok and you will get the project files are auto created Delete ValuesController and we could create a new controller
Create a new controller
Select webapi2 controller
Create a Model class and define
A request and response which should e the signature of api through which we are getting and posting data
Create a HTTPPOST method to your controller and use the request and response class
And Run the application then there is a default controller in Areas folder in your project inside helppage there is a controller HelpController ,this controller will help you to list out and sample out put and input data structure just type in the url /Help
While clicking a particular function it will shows the possible input and output Data structure
There is many method to debug the api code the most easy way i felt that using HTTPRequester
Which is a add-on to create a http request and is very useful i am using this to debug my web-api
You can Call the api as given below and put a break point on the controller
Invoke the api controller method through httprequester and you can see the data is passed to the api
The result came in the result window
I will explain the issues that i have faced when creating Web-api on next post
Please leave comment if this post helps you .
No comments:
Post a Comment