Sunday, 5 November 2017

WEB API

WEB API


API (Application Programing Interface).

set of subroutine definitions, protocols, and tools for building software and applications.

some kind of interface which has a set of functions that allow programmers to access specific features or data of an application, operating system or other services.

building HTTP based services

only supports HTTP protocol.

ideal platform for building RESTful services.

 supports ASP.NET request/response pipeline

Web API supports different formats of response data. Built-in support for JSON, XML, BSON format.

Web API can be hosted in IIS, Self-hosted or other web server that supports .NET 4.0+.



WEB API Versions:

Web API Version
Supported .NET Framework
Coincides with
Supported in
Web API 1.0
.NET Framework 4.0
ASP.NET MVC 4
VS 2010
Web API 2 - Current
.NET Framework 4.5
ASP.NET MVC 5
VS 2012, 2013
WEB API Vs WCF:

Web API
WCF
Open source and ships with .NET framework.
Ships with .NET framework
Supports only HTTP protocol.
Supports HTTP, TCP, UDP and custom transport protocol.
Maps http verbs to methods
Uses attributes based programming model.
Uses routing and controller concept similar to ASP.NET MVC.
Uses Service, Operation and Data contracts.
Does not support Reliable Messaging and transaction.
Supports Reliable Messaging and Transactions.
Web API can be configured using HttpConfiguration class but not in web.config.
Uses web.config and attributes to configure a service.
Ideal for building RESTful services.
Supports RESTful services but with limitations.
We can use the following third party tools for testing Web API.
  1. Fiddler
  2. Postman     
The following table lists possible action method names for each HTTP method:

HTTP Request Method
Possible Web API Action Method Name
Usage
GET
Get()
get()
GET()
GetAllStudent()
*any name starting with Get *
Retrieves data.
POST
Post()
post()
POST()
PostNewStudent()
*any name starting with Post*
Inserts new record.
PUT
Put()
put()
PUT()
PutStudent()
*any name starting with Put*
Updates existing record.
PATCH
Patch()
patch()
PATCH()
PatchStudent()
*any name starting with Patch*
Updates record partially.
DELETE
Delete()
delete()
DELETE()
DeleteStudent()
*any name starting with Delete*
Deletes record.






























WEBAPI vs MVC
Web API Controller
MVC Controller
Derives from System.Web.Http.ApiController class
Derives from System.Web.Mvc.Controller class.
Method name must start with Http verbs otherwise apply http verbs attribute.
Must apply appropriate Http verbs attribute.
Specialized in returning data.
Specialized in rendering view.
Return data automatically formatted based on Accept-Type header attribute. Default to json or xml.
Returns ActionResult or any derived type.
Requires .NET 4.0 or above
Requires .NET 3.5 or above








No comments:

Post a Comment