Thursday, 3 September 2020

ASP.Net WEB API Introduction

What is ASP.NET Web API ? Firsty We have to Understand What is API ? API Stands for "Application Programming Interface" is a set of software or piece of code which perform some specific   task and provides response in Universal format like (JSOn/XML/Other Formates) and It uses Client Server Constraints , In which Client sends request to the Server   for specific data defined into the Header and Server Process on the request and sends Response back to the Client. So Client perform his/her specific task without  interering from the server side and vise versa is also true.

Here Client may a Browser or it may be Console Application or it may be a web application User Interface or It may a Mobile Device or it may be IoT type things also.

 ASP.NET Web API :- ASP.NET Web API is a Http based service built on the top of the .NET Framework and these services deployed anywhere  on Internet and accessed by the clients like Browsers,Mobile Applications,Desktop Applications and IoT devices. It is Independent Software Architecture that use            Http protocol for sending and receiving data. It has a Client Server architecture in which Client sends request and server process on that request and sends response  back to the server in the Universal format like Json/XML/other formates.

ASP.Net Web API Sketch Diagram is shown below.


Explanation of above diagram :- In the above diagram we have write WebAPI for showing             details for voters based on the Areacode and we deployed this Web API on https://emsanalysis.com  on the Internet. In the above figure   there are four clients which are accessing these Web API by sending request https://emsanalysis.com/VoterDetails?AreaCode=12356  to server.  Server process on the request and response back to clients like Desktop Application,Mobile Devices,Iot,and Browsers. Response contains JSON data or XML data or any other formates which specify into the header and according to response data client parse the  data and display it.  The most common use of Web API is to build Restful Services.</strong> So now question is what is Restful Services ? REST stands for  Representational State Transfer is an architectural pattern that is mainly used for creating API that is based on HTTP protocol.

 REST includes some rules that is used for creation of API, which includes

        Client Server Pattern

        StateLess Requests

        Cacheability for Data

         HTTP Verbs for Communication

Client Server Architecure Rule:-   In this constraint Client Sends a request to Server and Server process on the Client request and sends response back to the clients so that in this scenario Client logic and server logic both are independent with each other.
Stateless Request Rule:-   Request between Client and Server should be stateless, it means no data or reuest should not save on server or can say that we should not be storing anything related to client on the server and communication between client and server must be Stateless for requests.The request from the client to the server should contain all the necessarry information to process the request. Ensure that each request should independently treated by the Server.
Cacheability for Data:-   Cacheability of data means to cache data which is frequent used by the client just like suppose you fetch List of departments in a oraganization so it will not change for a time so our services should have cache data for some time and when same request is generated by client then browser should serve data so that frequent access of server will reduce here and it will increase performance of API.
HTTP Verbs for Communication:-   In API firstly we have to understand about the Resources. So In API Resource means set of data we just want from the server for example List of All Departments (Departments) is the resource for us. Another one is List of all the Cities and their Postal Addresses is also the Resource. In API we have to write a method for resource so that we can access resource by a meaning full name like https://emsanalysis.com/Products.Here Products are the name of Resource.
HTTP verbs are the predefined set of rules which is used for accessing these resources so there are mainly used VERBS are
GET
PUT
POST
DELETE
GET is used for get the data from the server or we can say that it is the GET request for only fetch the list of data or some data from the server. For Example https://emsanalysis.com/Products is a GET request and it shows list of products to client.
POST is used for sending some data to server so we can add data into the body of message. so POST is generally send data for save or process data on server according to it.
PUT is used for sending some data to server for update data based on the conditions or data appended into the body of message. In simple we can say that it is UPDATE operation for WEB API.
DELETE is used for delete some data from the database server based on the key values appended into the URL or we can say that it is DELETE operation for WEB API.

No comments:

Post a Comment

Creating First WEB API Project from scratch ?

  For creating Web API project open your Visual Studio Editor and Create New Project as shown in below figure. Now you have to select  ASP.N...