WebAPI interview questions for experienced-Part2

 

Webapi2

This Blog is continuation of Part-1. if not visited. Please visit part-1.

https://webdevelopmentknowledge.blogspot.com/2021/02/WebAPI-interview-questions-for-experienced-Part1.html

In this blog we will be discussing some more questions frequently asked in Web API interviews.

1. What are Http Verbs? How to use it?

  • HTTP Verbs defines which type of request an endpoint should respond.
  •  In this we will define which type of Attribute should be used to consume a service. 
  • This are used to do operations like CRUD create ,Read, Update, Delete. 
  • We should define correct HTTP Verb to request a resource else it will give method not found error.

Mainly we use

GET - Retrieve data 

POST - Insert data

PUT - Update data

DELETE - delete the data.

2. How to use Attribute Routing?

Attribute Routing allows you to define the Route at Controller level or Action Method level in customized way.

To know more about Routing.

https://webdevelopmentknowledge.blogspot.com/2020/10/routing-in-aspnet-mvc.html

3. What is the use of Authorize Attribute?

  • In ASP.NET MVC we use Authorize Attribute to a Method to restrict the access to a method who are not Authenticated.
  • In Real time Application we use Anonymous Attribute to login methods which are used for login and all other methods will be restricted with Authorize Attribute. You must login first to navigate to the home page of an application. 

4. What is Stateless?

  • HTTP services are Stateless. That means when you send a request to server the state will be not saved in server for future requests. Their will be no relation between one request to another. Hence it is fast and lightweight.

5. What is Exception Handling?

  • Exception Handling plays vital role in all application. we should catch all the exceptions and handle it.
  • Whenever Server have an error we should provide User Friendly Error Page to the Users and Log the errors to a file or database for further investigation.

We can handle exception in 3 ways

1. Using Try catch blocks and handle the exception in catch block.

2. We can create global Exception handler which will overwrite "OnException" Method to handle it globally.

3. We can create Custom Filter Attribute to handle and overwrite "OnException" Method and that can be added at controller level or action Method level.

6.  What is Authentication?

Authentication is the process of verifying the user credentials with the system to identify the user belongs to system or not.

There are many ways of Authentication.

1. Password Based Authentication
2. Token Based Authentication
3. Multi Factor Authentication
4. Certificate Based Authentication
5. Biometric Based Authentication

7. What is Authorization?

  • Authorization is the process of access restriction to a Authenticated user to have access specific to his role.

8. What is Token Based Authorization?

  • Token Based Authorization is a protocol used to verify the user identity and as a response it will give a access token which is like a ticket to access the resource. User will have the access to resource till the expiry of token or if they quit the app or logged out then it will become invalid.
  • OAuth2 Token based Authorization will be implemented in modern Web API's to give protection to the resource and allow access to the Authenticated Users.
  • In this we many types of credential types like client credential, password grant type credential. 
  • So user will pass user credentials to Authenticate himself to utilize the resources.
  •  As a response we will pass one access token to the user. 
  • So for every Web API resource client need to send this access token in request header to authorize to get data from resource. 
  • Bearer token they will call it we need to pass as Authenticate bearer token in request. in server it will validate the access token and then give then it will give response. 
  • if access token expired or token invalid they cannot request the resource. 

9.  Which one is faster Stored Procedure or LINQ?

  •  Stored Procedures are faster as compared to LINQ query because for stored procedure execution   plan will be created immediately after creating the stored procedure. 
  •  So it will have execution plan hence it is faster and  also when a stored procedure is executed   database will cache the the executed stored procedure with parameters.
  •  if they request with same parameters it will directly take from cache and give result.
  •  So because of this Stored Procedure is faster than LINQ. 
  • LINQ queries need to execute as it is so it will take as regular time.

10. What are the return types of Web API ?

Web API supports below return types.

  • Void.
  • Primitive Type/Complex Type.
  • HttpResponseMessage.
  • IHttpActionResult.

When return type is IHttpActionResult Web API calls the ExecuteAsync method to create an HttpResponseMessage.  


      Bonus Question:

      This is mostly asked question in Interviews in LINQ.

      IEnumerable vs IQueryable 

      IEnumerable IQueryable
      IEnumerable is from System.Collections namespace IQueryable is from System.LINQ namespace
      IEnumerable can be used for In-memory collections like List, Array etc IQueryable can be used for Out-memory like database querying
      Select query executes on server side and load data in- memory and then apply filters Select query executes on server side with all filters
      used in the case of LINQ to objects and LINQ to XML used in querying on database like LINQ to SQL queries


      Thanks for Reading.

      follow my Facebook page to get new posts update.

      Link to my Linked in Profile.


      Post a Comment

      0 Comments