Part 2 - Basic Beginners introduction to WebApi | MVC Video based Tutorials by Hoven
Channel: Hoven
Date: 19/04/2014

For buying our complete videos visit = http://mvc.hoventrainings.com

OR

http://hoven-video-tutorials.azurewebsites.net

We are selling.

We are selling the entire collection of MVC video lectures at nominal prices. Get the complete DVD at your doorsteps.

Why Purchase ?
===========
By purchasing the complete set of MVC video lectures, you get the following benefits.

1. Watch lectures offline - no internet required.
2. Very good audio and video quality.
3. Learn in the comfort of your home, utilize your free time to upgrade your skills.
4. Learn on your Android Tablet also, anywhere, while travelling. No internet required.
5. Video lectures can be played on both a Windows PC(XP+, Vista, Win7, Win8) and Android OS(2.3 and up).

How to Purchase ?
=============

For details please visit http://mvc.hoventrainings.com

The Consignment
============

1. 99 video tutorials organized into chapters that simplify learning.
2. MVC projects/snippets/concepts explained in a very lucid and simple style.
3. Source code of the various examples discussesd in the videos.
4. MVC Interview Questions.
5. MVC E-Book.

How we Ship
==========

For customers in INDIA we shall send the DVD containing complete material through Speed Post. For customers outside INDIA we shall send you the download link(Google Drive) from where you have to download the entire contents at your own cost and effort.

Terms and Conditions Apply.

Transcription
=============

We shall create a WebApi Project
create a usual MVC project selecting basic template
since we have to serve data, let's begin by adding a model class
give it a name
add some properties
to the Controllers folder we shall add an "API" Controller
begin by adding a controller as usual
call it Products Controller
it inherits Controller class
we have to change it to Api Controller
type and change it
resolve
remove any existing functions
we shall now add an "API" to return a collection of objects
this will be an "API"
this is our completed "API"
name starts with GET
you should notice two things in this case
it's a GET, and takes no arguments
how to call and what will be the route mappings
inside App_Start folder there is a file called WebApiConfig
name of the route
route mapping
we can see that our URL should be api/products
because of this controller
"ID" is an optional parameter
action has not been specified in the route
because it can be deduced
by matching the count of arguments and type of request
in our present case we have zero arguments in our GetProducts function
so api/Products is sufficient to call our only "API"
we can run the project to see this output
ensure that your address bar has this URL
it calls the function GetProducts
you might be wondering what would happen if there are more than one contending functions
an exception would be thrown
the format you see are seeing is XML
we can change it to JSON
we have to type down two lines of code here
and remove XML formatter
just type these lines
we get JSON format now
we shall now add another "API"
this will return a single object
and it will take one argument
this code returns a product with matching "ID"