Its being long time after my last post, I hope you people missed me. I am writing this tutorial especially for my newbies programming students, who wants to know the basics of Web service as well as some tutorials to kick start with their Projects.
Before starting tutorial I would first like to take you on background tour of web service and the importance of the web service in today's world. As we all know, we are in an era in which everything is a part of cloud service and every thing is connected to each other, where laptops, tablets, PC, mobiles and all the portable devices are the main consumer of Cloud. When we talk about Cloud we mean some unknown place where your data stores and you consume it, and its available everywhere.
For making things more digestible I would like to give you an example of Facebook, we can access it from anywhere, and from any device. The first thing that pops in your mind will be "hey wait, isn't fb is a website?, not a cloud?" , and my answer will be "No its a Cloud". Why cloud? because it provides you service and not 100% users use it as a website, they have applications in their tablets, phones, some people use its chatting app from desktop. Facebook have built in Cloud service that provides service to website, mobiles, tablets, desktop app and so on.
Bored?, Lets Get Started with web service, there are certain things that you must know, web service can be created through any language, platform and there are certain types of services that we use know days 1) RESTful and 2) SOAP, there are more but I don't want to go to much deep.
In the last we have web service languages in which JSON (JavaScript Object Notation) and XML (eXtensible Markup Language) Commonly used for data transferring.
Just remember to go through my Jump Start tutorial for MVC this will help you understanding MVC Architecture and Web API works on MVC.
Now, start your Visual Studio and create yourself a New Project and named it something nice, I named it MvcApiWebApplication.
Now Select Web Api Template from List
And press OK. You will get something similar to image below.
Now, have a look to Solution Explorer you will see Project similar to MVC Application that we have already studied before. Now go to Controllers Folder in the Solution Explorer. You will find 2 file in it HomeController and ValuesController, the file that we are interest in is ValuesController. Now Double Click on the file to open, most of the readers will be cursing me at this point "we know how to open file, its not our first time".
If you have a closer look you will find this Controller Class inherited to ApiController Unlikely of ordinary Controller. And second thing that you have noticed, are the methods there are five methods 2 Get, a Post, a Put and a Delete. These name of the methods will be consistent in each every file you create for ApiController. Since Web Api is derived from RESTful web service standards, and one of the standard is to follow Http Methods (GET, POST, PUT, DELETE, HEAD etc) for the service consumption. To give you clear view of Http Methods lets have an example of simple web application, when we type web address into the URL on browser and hit enter, the Command that browser runs is "GET" with your given URL as a web request. Similarly when you authenticate your credentials to website while providing username and password and clicks submit button, Browser runs "POST" command with your URL and data that you filled. Similarly we have "PUT" Command to Update some data and "DELETE" for delete record or records, but PUT and DELETE merely used in Web application, but plays vital role in web service.
This is just a dummy demonstration that Visual Studio create for you
Before starting tutorial I would first like to take you on background tour of web service and the importance of the web service in today's world. As we all know, we are in an era in which everything is a part of cloud service and every thing is connected to each other, where laptops, tablets, PC, mobiles and all the portable devices are the main consumer of Cloud. When we talk about Cloud we mean some unknown place where your data stores and you consume it, and its available everywhere.
For making things more digestible I would like to give you an example of Facebook, we can access it from anywhere, and from any device. The first thing that pops in your mind will be "hey wait, isn't fb is a website?, not a cloud?" , and my answer will be "No its a Cloud". Why cloud? because it provides you service and not 100% users use it as a website, they have applications in their tablets, phones, some people use its chatting app from desktop. Facebook have built in Cloud service that provides service to website, mobiles, tablets, desktop app and so on.
Bored?, Lets Get Started with web service, there are certain things that you must know, web service can be created through any language, platform and there are certain types of services that we use know days 1) RESTful and 2) SOAP, there are more but I don't want to go to much deep.
In the last we have web service languages in which JSON (JavaScript Object Notation) and XML (eXtensible Markup Language) Commonly used for data transferring.
Just remember to go through my Jump Start tutorial for MVC this will help you understanding MVC Architecture and Web API works on MVC.
Now, start your Visual Studio and create yourself a New Project and named it something nice, I named it MvcApiWebApplication.
Now Select Web Api Template from List
And press OK. You will get something similar to image below.
Now, have a look to Solution Explorer you will see Project similar to MVC Application that we have already studied before. Now go to Controllers Folder in the Solution Explorer. You will find 2 file in it HomeController and ValuesController, the file that we are interest in is ValuesController. Now Double Click on the file to open, most of the readers will be cursing me at this point "we know how to open file, its not our first time".
If you have a closer look you will find this Controller Class inherited to ApiController Unlikely of ordinary Controller. And second thing that you have noticed, are the methods there are five methods 2 Get, a Post, a Put and a Delete. These name of the methods will be consistent in each every file you create for ApiController. Since Web Api is derived from RESTful web service standards, and one of the standard is to follow Http Methods (GET, POST, PUT, DELETE, HEAD etc) for the service consumption. To give you clear view of Http Methods lets have an example of simple web application, when we type web address into the URL on browser and hit enter, the Command that browser runs is "GET" with your given URL as a web request. Similarly when you authenticate your credentials to website while providing username and password and clicks submit button, Browser runs "POST" command with your URL and data that you filled. Similarly we have "PUT" Command to Update some data and "DELETE" for delete record or records, but PUT and DELETE merely used in Web application, but plays vital role in web service.
This is just a dummy demonstration that Visual Studio create for you
TAGS :
.net 4.5 |
Code first |
easy web service |
EF |
Fiddler |
JSON |
Jump Start |
MVC |
RESTful |
Visual Studio 2013 |
VS 2013 |
Web API |
XML |
COMMENTS