What is ASP.Net Web API, why & when to use

asp.net web api tutorial for beginners web api tutorial asp.net web api web api examples asp.net web api interview questions web api vs wcf web api vs web service

What is ASP.Net Web API, why & when to use

What is ASP.Net Web API, what is RESTFul service, What is the difference between WCF and Web API and when to use over other. These are the main points which we going to discuss in this starting article, then we will create our own Web API project and look each and every single type of methods like get, post, put, delete. We will also use the Entity Framework to get and post the data to SQL Server.

What is ASP.Net Web API

ASP.Net Web API is a framework to build Web API Services, that means HTTP Based services on top of the .Net Framework.

It is commonly used to build RESTFul services, these services can be consume by different type of clients, like

  • Browser
  • Mobile Applications
  • Desktop Applications
  • Others: Object having IP Address and can communicate with internet devices like Laptop, Desktop, Mobile, Cars, and other electronic devices.

ASP.Net Web API are mostly used for RESTFul service but we can also create services which are not restful in nature.

What is restful service REST stands for Representational State Transfer, which is an architectural style for networked hypermedia applications, it is primarily used to build Web services that are lightweight, maintainable, and scalable. A service based on REST is called a RESTful service, it was introduces first time in the year 2000.

REST Constraints

  • CLIENT: Send the request to service and wiat for Response
  • SERVER: Accept request and Send Response
  • STATELESS: Don't store any information of client on the server, it means each request treated as an independent request
  • CACHEABLE: Common un-changeable data like list of states can be cached for a particular time and serve directly without process, it can increase the performance significantly.
  • UNIFORM INTERFACE: HTTP standard to describe communication like GET, PUT, POST, DELETE etc.
  • LAYERED SYSTEM: ASP.Net Web API can be used as a layer
  • CODE ON DEMAND (Optional): using code on demanad reduces visibility, which is why this constraint is optional. Also, not every API needs this kind of flexibility.

Why Web API while we already have WCF

WCF configuration is quite complex to use as RESTFul service while Web API is specially created for this purpose, easy to configure, easy to understan, easy to add routing

When to use WCF Over Web API

  • Creating services that are transport/protocol independent
  • Single service with multiple end points
  • If we have an existing SOAP service we must support it and want to add expose for more clients
  • .Net 3.5 limitations

In next article we will create a ASP.Net Web API from scratch.

Ali Adravi Having 13+ years of experience in Microsoft Technologies (C#, ASP.Net, MVC and SQL Server). Worked with Metaoption LLC, for more than 9 years and still with the same company. Always ready to learn new technologies and tricks.
  • web-api
  • wcf
  • asp.net
By Ali Adravi On 13 Jul, 17  Viewed: 391

Other blogs you may like

Angularjs ui-routing with Web API

I found most of .Net developer whether they are ASP.Net developer or MVC developer, they face to start and how to create the Angularjs application structure. In this article we will start from an empty project with Web API 2.0. First of all we will create very simple application with three... By Ali Adravi   On 18 Jul 2015  Viewed: 2,589

Upload multiple image in multiple size with progress bar in asp.net

In asp.net there is not control to select multiple files and upload them once with progress bar, so we will use a small third party DLL to achieve this functionality. We will use Flajaxian FileUploader, you can download it from [http://www.flajaxian.com][1] We will create three different images... By Hamden   On 12 Jul 2012  Viewed: 4,949

Check/Uncheck all checkboxes in asp.net by javascript

I was searching for select/deselect all checkboxes code into a gridview. I found most of them only provide to select and deselet all the checkboxes if any of the checkbox is unselected into grid the main checkbox is not affecting. I further try to search some useful code but could not found any... By Ali Adravi   On 10 Jul 2012  Viewed: 3,421

MVC model validation for email from database in asp.net

There are many cases where we need to validate the value in controls before submitting to the database, so let's discuss email validation like format, length and existence into database. We will walk through in this article, how to validate entered user email from database, whether email is already... By Ali Adravi   On 05 Jan 2013  Viewed: 4,710

Routing with asp.net web forms application

Microsoft .NET Framework 3.5 SP1 introduced a routing engine to the ASP.NET runtime. The routing engine can decouple the URL in an incoming HTTP request from the physical Web Form that responds to the request, allowing you to build friendly URLs for your Web applications. Let's start make our... By Ali Adravi   On 05 Jan 2013  Viewed: 1,719