Asp.Net WebApi Interview Questions
Interview Questions 1 – Explain what is REST and RESTFUL?
Representational State Transfer (REST) is an architectural style that defines a set of constraints to be used for creating web services and APIs. It has defined guidelines for creating services which are scalable. REST used with HTTP protocol using its verbs GET, PUT, POST and DELETE.
RESTFUL is referred for web services/ WebApi written by applying REST architectural concept. It focuses on system resources and how state of resource should be transported over HTTP protocol to different clients written in different language. In RESTFUL web service/API HTTP methods like GET, POST, PUT and DELETE can be used to perform CRUD operations.
Interview Questions 2 – What is ASP.NET WebAPI?
ASP.NET WebAPI is a framework which helps developers to build HTTP services for broader range of clients including web browsers as well as mobile devices on top of .NET Framework.
Using ASP.NET Web API, we can create non-SOAP based services.
Interview Questions 3 – What are the Advantages of Using ASP.NET WebAPI?
The advantages of using ASP.NET Web API are:
- Create resource-oriented services using the full features of HTTP
- Exposing services to a variety of clients easily like browsers or mobile devices, etc.
- It works the HTTP way using standard HTTP verbs like GET, POST, PUT, DELETE, etc. for all CRUD operations
- Complete support for routing
- Response generated in JSON or XML format using MediaTypeFormatter
- It has the ability to be hosted in IIS as well as self-host outside of IIS
- Supports Model binding and Validation
- Filters
- Web API encourages TDD (Test Data Driven) approach in the development of RESTful services.
Interview Questions 4 – Why select WebAPI?
- It is used to create simple, non-SOAP-based HTTP Services
- It is based on HTTP and easy to define, expose and consume in a REST-ful way.
- It is lightweight architecture and ideal for devices that have limited bandwidth like smartphones.
Interview Questions 5 – Is it right that ASP.NET WebAPI has replaced WCF?
It’s a not at all true that ASP.NET Web API has replaced WCF. In fact, it is another way of building non-SOAP based services, i.e., plain XML or JSON string.
Interview Questions 6 – Mention what tools are required to test your web API?
SOAPUI tool for SOAP WS, Postman and Firefox “poster” plugin for RESTFUL services.
Interview Questions 7 – Mention what are the HTTP methods supported by REST?
HTTP methods supported by REST are:
- GET: It requests a resource at the request URL. It should not contain a request body as it will be discarded. Maybe it can be cached locally or on the server.
- POST: It submits information to the service for processing; it should typically return the modified or new resource
- PUT: At the request URL it update the resource
- DELETE: At the request URL it removes the resource
- OPTIONS: It indicates which techniques are supported
- HEAD: About the request URL it returns meta information
Interview Questions 8 – What are main return types supported in Web API?
A Web API controller action can return following values:
- Void – It will return empty content
- HttpResponseMessage – It will convert the response to an HTTP message.
- IHttpActionResult – internally calls ExecuteAsync to create an HttpResponseMessage
- Other types – You can write the serialized return value into the response body
Interview Questions 9 – Web API supports which protocol?
Web API supports HTTP protocol.
Interview Questions 10 – Who can consume WebAPI?
WebAPI can be consumed by any client which supports HTTP verbs such as GET, PUT, DELETE, POST. As WebAPI services don’t need any configuration, they are very easy to consume by any client. Infract, even portable devices like Mobile devices can easily consume WebAPI which is certainly the biggest advantages of this technology.
Interview Questions 11 – Which .NET framework supports Web API?
NET 4.0 and above version supports web API.
Interview Questions 12 – Web API uses which of the following open-source library for JSON serialization?
Web API uses Json.NET library for JSON serialization.
Interview Questions 13 – By default, Web API sends HTTP response with which status code for all the uncaught exception?
500 – Internal Server Error
Interview Questions 14 – What is the biggest disadvantage of “Other Return Types” in Web API?
The biggest disadvantage of this approach is that you cannot directly return an error code like 404 error.
Interview Questions 15 – What is Web API Routing in Asp.Net WebApi?
Routing in Web API is pattern matching like in MVC. All routes are registered in Route Tables.
Asp.Net WebApi Interview Questions – Cont.