{"id":19361445,"url":"https://github.com/kansiris/asp.net-webapi-interview-questions","last_synced_at":"2026-02-25T18:03:52.876Z","repository":{"id":106184510,"uuid":"195599784","full_name":"kansiris/ASP.NET-webapi-Interview-Questions","owner":"kansiris","description":null,"archived":false,"fork":false,"pushed_at":"2019-07-12T13:56:00.000Z","size":13,"stargazers_count":20,"open_issues_count":0,"forks_count":10,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-29T15:39:11.819Z","etag":null,"topics":["asp","http-protocol","http-verbs","interview","interview-preparation","interview-questions","net-mvc","rest-ful","rest-principle","rest-stands","soap","wcf-rest","xml"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kansiris.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-07T02:03:17.000Z","updated_at":"2025-07-09T16:27:38.000Z","dependencies_parsed_at":"2023-06-16T01:15:40.248Z","dependency_job_id":null,"html_url":"https://github.com/kansiris/ASP.NET-webapi-Interview-Questions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kansiris/ASP.NET-webapi-Interview-Questions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kansiris%2FASP.NET-webapi-Interview-Questions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kansiris%2FASP.NET-webapi-Interview-Questions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kansiris%2FASP.NET-webapi-Interview-Questions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kansiris%2FASP.NET-webapi-Interview-Questions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kansiris","download_url":"https://codeload.github.com/kansiris/ASP.NET-webapi-Interview-Questions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kansiris%2FASP.NET-webapi-Interview-Questions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29833701,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T17:57:15.019Z","status":"ssl_error","status_checked_at":"2026-02-25T17:56:11.472Z","response_time":61,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asp","http-protocol","http-verbs","interview","interview-preparation","interview-questions","net-mvc","rest-ful","rest-principle","rest-stands","soap","wcf-rest","xml"],"created_at":"2024-11-10T07:23:17.943Z","updated_at":"2026-02-25T18:03:52.834Z","avatar_url":"https://github.com/kansiris.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# ASP.NET WEB API Interview Questions \u0026 Answers\n\n\u003e Click :star:if you like the project. Pull Request are highly appreciated. Follow me [@kansiris87](https://twitter.com/kansiris87) for technical updates.\n\n### Table of Contents\n\n| No. | Questions |\n|---- | ---------\n|1    | [What is REST?](#What is REST?)|\n|2 | [Explain REST principle?](#Explain REST principle?)|\n|3 | [What is difference between REST and SOAP?](#What is difference between REST and SOAP?)|\n|4 | [What is ASP.NET WEB API?](#What is ASP.NET WEB API?)|\n|5 | [Why choose ASP.NET WEB API?](#Why choose ASP.NET WEB API?)|\n|6 | [What is difference between WCF and ASP.NET WEB API and WCF REST and Web Service?](#What is difference between WCF and ASP.NET WEB API and WCF REST and Web Service?)|\n|7 | [Which one to choose between WCF and WEB API?](#Which one to choose between WCF and WEB API?)|\n|8 | [What is the difference between ASP.NET MVC and ASP.NET WEB API?](#HWhat is the difference between ASP.NET MVC and ASP.NET WEB API?)|\n|9 | [Can you return view by using WEB API method?](#Can you return view by using WEB API method?)|\n|10| [Can you change WEB API action name like ASP.NET MVC?](#Can you change WEB API action name like ASP.NET MVC?)|\n\n|1    | [Can you restrict a WEB API action method to be invoked only by HTTP GET, POST, PUT or DELETE?](#Can you restrict a WEB API action method to be invoked only by HTTP GET, POST, PUT or DELETE?)|\n|2 | [How to call WEB API in ASP.NET MVC?](#How to call WEB API in ASP.NET MVC?)|\n|3 | [How ASP.NET API routing is different from ASP.NET MVC routing?](#How ASP.NET API routing is different from ASP.NET MVC routing?)|\n|4 | [How to enable Attribute Routing in ASP.NET WEB API2?](#How to enable Attribute Routing in ASP.NET WEB API2?)|\n|5 | [How to define attribute routing in ASP.NET WEB API2?](#How to define attribute routing in ASP.NET WEB API2?)|\n\n\n### What is REST?\t\nREST stands for Representational State Transfer. This is a protocol for exchanging data over a distributed environment. REST is an architectural style which treat each service as a resource and access data by HTTP protocol methods like GET, POST, PUT, and DELETE.\n\nREST-style architectures consist of clients and servers. Clients initiate requests to servers who process these requests and return responses based on these requests. These requests and responses are built around the transfer of representations of these resources.\n\n### Explain REST principle?\t\n\nREST is a set of principles that define how Web standards, such as HTTP and URIs, are supposed to be used. There are five important REST principle as given below –\n\nAddressable Resources - Each resource should be identified by a URI (unique identifier)\n\nSimple and Uniform Interfaces - REST is based on HTTP protocol so use HTTP GET, POST, PUT and DELETE method to perform actions. This make REST simple and uniform.\n\nRepresentation Oriented- Representation of resources are exchanged. GET is used to return a representation and PUT, POST passes representation to the server so that underlying resources may change. Representation may be in many formats like XML, JSON etc.\n\nCommunicate Stateless - An application may has state but there is no client session data stored on the server. Any session specific data should be held and maintained by the client and transferred to the server with each request as needed.\n\nCacheable - Clients should be able to cache the responses for further use.\n\n### What is difference between REST and SOAP?\t\n\nThe difference between REST and SOAP is given below:\nSOAP\nREST\nSOAP stands for Simple Object Access Protocol\nREST stands for REpresentational State Transfer.\nIt is an XML based protocol built on the top of HTTP or sometimes TCP/IP, SMTP.\nREST is not a protocol but it is an architectural style i.e.resource-based architecture.\nSOAP has specifications for both stateless and stateful implementation.\nREST is completely stateless.\nSOAP enforces message format as XML.\nREST does not enforces message format as XML or JSON.\nSOAP has a defined standard specification.For example, WS-Security is the specification for implementing security.\nIt has no defined standard specifications.\nThe SOAP message consists of an envelope which includes SOAP headers and body to store the actual information you want to send.\nREST uses the HTTP build-in headers (with a variety of media-types) to carry meta information and use the GET,POST, PUT and DELETE verbs to perform CRUD operations.\nSOAP uses interfaces and named operations to expose your service.\nREST uses URI and methods like (GET, PUT, POST, DELETE) to expose resources.\nPerformance is slow as compared to REST.\nREST is fast as compared to SOAP.\n\n\n### What is ASP.NET WEB API?\t\n\nASP.NET WEB API is a framework for building HTTP services that can be consume by a broad range of clients including browsers, mobiles, iphone and tablets. It is very similar to ASP.NET MVC since it contains the MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection. But it is not a part of the MVC Framework.\nIt is a part of the core ASP.NET platform and can be used with MVC and other types of Web applications like ASP.NET WebForms. It can also be used as a stand-alone Web services application.\nASP.NET WEB API features\n    1. It supports convention-based CRUD Actions since it works with HTTP verbs GET, POST, PUT and DELETE.\n    2. Responses have an Accept header and HTTP status code.\n    3. Responses are formatted by WEB API’s MediaTypeFormatter into JSON, XML or whatever format you want to add as a MediaTypeFormatter.\n    4. It may accepts and generates the content which may not be object oriented like images, PDF files etc.\n    5. It has automatic support for OData. Hence by placing the new [Queryable] attribute on a controller method that returns IQueryable, clients can use the method for OData query composition.\n    6. It can be hosted with in the applicaion or on IIS.\n    7. It also supports the MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection that makes it more simple and robust.\n\n### Why choose ASP.NET WEB API?\t\n\nToday, a web-based application is not enough to reach it's customers. People are very smart, they are using iphone, mobile, tablets etc. devices in its daily life. These devices also have a lot of apps for making the life easy. Actually, we are moving from the web towards apps world.\n\n\n\n\n\n\nSo, if you like to expose your service data to the browsers and as well as all these modern devices apps in fast and simple way, you should have an API which is compatible with browsers and all these devices.\n\nFor example twitter, facebook and Google API for the web application and phone apps.\n\nWEB API is the great framework for exposing your data and service to different-different devices. Moreover WEB API is open source an \nideal platform for building REST-ful services over the .NET Framework. Unlike WCF Rest service, it use the full featues of HTTP (like URIs, request/response headers, caching, versioning, various content formats) and you don't need to define any extra config settings for different devices unlike WCF Rest service.\n\n### Why to choose WEB API\n\n1. If we need a Web Service and don’t need SOAP, then ASP.NET WEB API is best choice.\n\n2. It is used to build simple, non-SOAP-based HTTP Services on top of existing WCF message pipeline.\n\n3. It doesn't have tedious and extensive configuration like WCF REST service.\n\n4. Simple service creation with WEB API. With WCF REST Services, service creation is difficult.\n\n5. It is only based on HTTP and easy to define, expose and consume in a REST-ful way.\n\n6. It is light weight architecture and good for devices which have limited bandwidth like smart phones.\n\n7. It is open source.\n\n\n### What is difference between WCF and ASP.NET WEB API and WCF REST and Web Service?\n\n.NET framework has a number of technologies that allow you to create HTTP services such as Web Service, WCF and now WEB API. There are following differences among these four:\n\nWeb Service\n\n1. It is based on SOAP and return data in XML form.\n\n2. It supports only HTTP protocol.\n\n3. It is not open source but can be consumed by any client that understands xml.\n\n4. It can be hosted only on IIS.\n\n\nWCF\n\n1. It is also based on SOAP and return data in XML form.\n\n2. It is the evolution of the web service (ASMX) and support various protocols like TCP, HTTP, HTTPS, Named Pipes, MSMQ.\n\n3. The main issue with WCF is, its tedious and extensive configuration.\n\n4. It is not open source but can be consumed by any client that understands xml.\n\n5. It can be hosted with in the application or on IIS or using window service.\n\nWCF Rest\n\n1. To use WCF as WCF Rest service you have to enable webHttpBindings.\n\n2. It support HTTP GET and POST verbs by [WebGet] and [WebInvoke] attributes respectively.\n\n3. To enable other HTTP verbs you have to do some configuration in IIS to accept request of that particular verb on .svc files\n\n4. Passing data through parameters using a WebGet needs configuration. The UriTemplate must be specified\n\n5. It support XML, JSON and ATOM data format.\n\nWEB API\n\n1. This is the new framework for building HTTP services with easy and simple way.\n\n2. WEB API is open source an ideal platform for building REST-ful services over the .NET Framework.\n\n3. Unlike WCF Rest service, it use the full features of HTTP (like URIs, request/response headers, caching, versioning, various content \nformats)\n\n4. It also supports the MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection, unit testing that makes it more simple and robust.\n\n5. It can be hosted with in the application or on IIS.\n\n6. It is light weight architecture and good for devices which have limited bandwidth like smart phones.\n\n7. Responses are formatted by WEB API’s MediaTypeFormatter into JSON, XML or whatever format you want to add as a MediaTypeFormatter.\n\n### Which one to choose between WCF and WEB API?\t\n\nThe following points help you to choose between WCF and WEB API:\n\n1. Choose WCF when you want to create a service that should support special scenarios such as one way messaging, message queues, duplex communication etc.\n\n2. Choose WCF when you want to create a service that can use fast transport channels when available, such as TCP, Named Pipes, or maybe even UDP (in WCF 4.5), and you also want to support HTTP when all other transport channels are unavailable.\n\n3. Choose WEB API when you want to create resource-oriented services over HTTP that can use the full features of HTTP (like URIs, request/response headers, caching, versioning, various content formats).\n\n4. Choose WEB API when you want to expose your service to a broad range of clients including browsers, mobiles, iphone and tablets.\n\n\n### What is the difference between ASP.NET MVC and ASP.NET WEB API?\t\n\nThere are following differences between ASP.NET MVC and WEB API:\n\n1. ASP.NET MVC is used to create web applications that return both views and data but ASP.NET WEB API is used to create full blown HTTP services with easy and simple way that returns only data not view.\n\n2. WEB API helps to build REST-ful services over the .NET Framework and it also support content-negotiation(it's about deciding the best response format data that could be acceptable by the client. it could be JSON,XML,ATOM or other formatted data), self-hosting which are not in MVC.\n\n3. WEB API also takes care of returning data in particular format like JSON, XML or any other based upon the Accept header in the request and you don't worry about that. MVC only return data in JSON format using JsonResult.\n\n4. In WEB API the request are mapped to the actions based on HTTP verbs but in MVC it is mapped to actions name.\n\n5. ASP.NET WEB API is new framework and part of the core ASP.NET framework. The model binding, filters, routing and others MVC features exist in WEB API are different from MVC and exists in the new System.Web.Http assembly. In MVC, these features exist within System.Web.Mvc. Hence WEB API can also be used with ASP.NET and as a stand-alone service layer.\n\n6. You can mix WEB API and MVC controller in a single project to handle advanced AJAX requests which may return data in JSON, XML or any others format and building a full blown HTTP service. Typically, this will be called WEB API self-hosting.\n\n7. When you have mixed MVC and WEB API controller and you want to implement the authorization then you have to create two filters one for MVC and another for WEB API since both are different.\n\n8. Moreover, WEB API is light weight architecture and except the web application it can also be used with smart phone apps.\n\n### Can you return view by using WEB API method?\t\n\nUnlike ASP.NET MVC, WEB API is used to return only data. The data can be string, JSON, XML, Text etc. It cannot return View like ASP.NET MVC.\n\n### Can you change WEB API action name like ASP.NET MVC?\t\n\nLike ASP.NET MVC, you can also change WEB API action name by using ActionName attribute as given below:\n\n[HttpGet] [ActionName(\"GetProducts\")]\npublic IEnumerable\u003cProduct\u003e ProductList()\n{\n    return db.Products.AsEnumerable();\n    }\n    \n### Can you restrict a WEB API action method to be invoked only by HTTP GET, POST, PUT or DELETE?\t\n\nLike ASP.NET MVC, you can also restrict WEB API action method to be invoked only by a specific HTTP request by applying HttpGet or HttpPost or HttpPut or HttpDelete attribute.\n\nIf you want to restrict an action method for HTTP Get request only then decorate it with HttpGet action method selector attribute as given below:\n\n[HttpGet]\npublic IEnumerable\u003cProduct\u003e ProductList()\n{\n    return db.Products.AsEnumerable();\n    }\n    \n###  How to call WEB API in ASP.NETMVC?\t\n\nASP.NET WEB API can be called by using HttpClient and WEB API address as given below:\n\npublic class ProductController : Controller\n{\nHttpClient Client = new HttpClient();\nUri BaseAddress = new Uri(\"http://localhost:131/\"); \npublic ActionResult Index()\n{\nClient.BaseAddress = BaseAddress;\nHttpResponseMessage response = Client.GetAsync(\"productservice/GetProducts\").Result;\nif (response.IsSuccessStatusCode)\n{\nvar data = response.Content.ReadAsAsync\u003cIEnumerable\u003cProduct\u003e\u003e().Result;\n    return View(data);\n    }\nreturn View();\n}\n    }\n    \n    \n### How ASP.NET API routing is different from ASP.NET MVC routing?\t\n\nASP.NET MVC and ASP.NET WEB API both use routing to monitor incoming request and at least one route is defined in order to function. The difference between these two routing is given below:\n\n1. In WEB API route pattern {action} parameter is optional but you can include an {action} parameter. In ASP.NET MVC {action} parameter is mandatory.\n\n2. The action methods defined in the API controller must either have the HTTP action verbs (GET, POST, PUT, DELETE) attribute or have one of the HTTP action verbs as a prefix for the actions methods name. In ASP.NET MVC, by default an action method can be called by HTTP GET or POST verbs and for using others HTTP verbs you need to defined as an attribute.\n\n3. Unlike ASP.NET MVC, Web API can receive only one complex type as a parameter.\n\n### How to enable Attribute Routing in ASP.NET WEB API2?\t\n\nEnabling attribute routing in your ASP.NET WEB API2 is simple, just add a call to MapHttpAttributeRoutes()\nmethod with in Register() method of WebApiConfig.cs file.\n\npublic static class WebApiConfig\n{\npublic static void Register(HttpConfiguration config)\n{\n//enabling attribute routing config.MapHttpAttributeRoutes();\n}\n}\n\nYou can also combine attribute routing with convention-based routing.\n\npublic static class WebApiConfig\n{\npublic static void Register(HttpConfiguration config)\n{\n\n//enabling attribute routing config.MapHttpAttributeRoutes();\n// Convention-based routing. config.Routes.MapHttpRoute( name: \"DefaultApi\",\n\nrouteTemplate: \"api/{controller}/{id}\", defaults: new { id = RouteParameter.Optional });\n\n}\n}\n\n### How to define attribute routing in ASP.NET WEB API2?\t\n\nLike ASP.NET MVC5, you can also define attribute routing in WEB API2 at controller level and action level as shown below:\n\n1. Controller level routing – You can define routes at controller level which apply to all actions within the controller unless a specific route is added to an action.\n\n[RoutePrefix(\"Service/User\")]\npublic class UserController : ApiController\n{ \n//GET route: api/User\npublic IEnumerable\u003cstring\u003e Get()\n{\n    return new string[] { \"value1\", \"value2\" };\n    \n    }\n\n[Route(\"{id}\")] //GET route: Service/User/1 public string Get(int id)\n{\nreturn \"value\";\n}\n\n[Route(\"\")] //POST route: Service/User/ public void Post([FromBody]string value)\n{\n}\n}\n\n• Action level routing – You can define routes at action level which apply to a specific action with in the controller.\n\npublic class UserController : ApiController\n{\n//GET route: api/User\n\npublic IEnumerable\u003cstring\u003e Get()\n{\n    return new string[] { \"value1\", \"value2\" };    \n    }\n    \n[Route(\"Service/User/{id}\")] //GET route: Service/User/1 public string Get(int id)\n{\nreturn \"value\";\n}\n[Route(\"Service/User/\")] //POST route: Service/User/ public void Post([FromBody]string value)\n{\n}\n}\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkansiris%2Fasp.net-webapi-interview-questions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkansiris%2Fasp.net-webapi-interview-questions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkansiris%2Fasp.net-webapi-interview-questions/lists"}