Web API (Application Programming Interface), is an API that can be accessed through HTTP protocol. It is basically considered the best platform for revealing or uncovering data and services to various different services. It is a tool that can be used to push data to a server and can be accessed by server code. It can be built or developed using various technologies like java, ASP.NET, etc. Web API:
It does not have any specific data type. It can return data of any type depending on the business requirement. There are many HTTP methods like GET, POST, PUT, Patch, Delete, which can return data in different formats depending on the use case.
WCF is a framework used for developing SOAP (Service-oriented applications).
This framework is used for developing, configuring, and deploying, or implementing
network-distributed services.
Web API is an application programming interface for both web browsers and web servers. Browser API simply extends or increases the functionality of web browsers whereas Server API simply extends or increases the functionality of web server.
Web API is considered the best choice over WCF because of the following reasons:
REST (Representation State Transfer) API is basically an architectural style
that makes productive use of existing technology and protocols of the web.
It is a set of rules that developers need to follow when they develop their API or services
that are scalable. It is used with HTTP protocol using its verbs such as GET, DELETE, POST, PUT.
RESTful API is simply referred to as web services executing such as architecture.
See also REST vs. RESTful: The Difference and Why the Difference Doesn’t Matter
REST is very important and beneficial in Web API because of the following reasons:
REST (Representational State Transfer) is a new and improved form of web service. It describes the architectural style of networked systems. It does not require greater bandwidth when requests are sent to the server. It just includes JSON message. SOAP (Simple Object Access Protocol) is a simple and lightweight protocol that is generally used for exchanging structured and typed information on the Web. It works mostly with HTTP and RPC (Remote Procedure Call). This protocol is mainly used for B2B applications one can define a data contract with it. SOAP messages are heavier in content and therefore use greater bandwidth.
It is basically an enhanced and modified feature of Web API. This new version supports such new features as:
In web API, media type formatters are classes that are responsible for serialization data. Because of serializing request/response data, Web API can understand request data format in a better way and send data in a format that the client expects. It simply specifies data that is being transferred among client and server in HTTP response or request.
Web API generally supports only HTTP protocol.
Filters are basically used to add extra logic at different levels of Web API framework request processing.
Web Api includes the following types of filters:
Web API provides flexibility in terms of handling errors. Exception handling is a technique that is used to handle run-time errors in application code. We can use HttpResponseException, HttpError, Exception filters, register exception filters, Exception handlers to handle errors. Exception filter can be used to identify unhandled exceptions on actions or controllers. Exception handlers can be used to identify any type of unhandled exception application-wide, and HttpResponseException can be used when there is the possibility of an exception.
One can register exception filter globally using following code:
GlobalConfiguration.Configuration.Filters.Add (
new MyTestCustomerStore.NotImplExceptionFilterAttribute());
MVC (Model, View, and Controller) is basically an application design pattern that comprises three interconnect parts i.e., model, view, and controller. It allows coders to factor out different components of the application and update them more easily. Its main purpose is to display patterns in structure for keeping display and data separate to enable both of them to change without affecting others.
ASP.NET Web API is a framework that is used for developing HTTP services to provide responses to client requests. It can be accessed in different applications on different platforms. It is provided for developing and consuming HTTP-based services on top of .NET Framework. These services can be used by such clients as:
Usage of ASP.NET Web API provides the following advantages: