GitHub - Devinterview-Io - Asp-Net-Web-Api - ? ASP - Net Web API Coding Interview Questions and Answers For Developers
GitHub - Devinterview-Io - Asp-Net-Web-Api - ? ASP - Net Web API Coding Interview Questions and Answers For Developers
🟣 ASP.NET Web API coding interview questions and answers for developers.
2
stars
0
forks
Star
Notifications
main
Go to file
Devinterview-io … on 22 Jan
View code
Using ASP.NET Web API, we can create non-SOAP based services like plain XML or JSON
strings, etc. with many other advantages including:
Source: codeproject.com
https://github.com/Devinterview-io/asp-net-web-api 1/17
21/09/2021, 12:55 GitHub - Devinterview-io/asp-net-web-api: 🟣 ASP.NET Web API coding interview questions and answers for developers.
Answer:
500 – Internal Server Error
Consider:
[Route("CheckId/{id}")]
[HttpGet]
return Ok(id);
Source: docs.microsoft.com
Source: c-sharpcorner.com
Answer:
https://github.com/Devinterview-io/asp-net-web-api 2/17
21/09/2021, 12:55 GitHub - Devinterview-io/asp-net-web-api: 🟣 ASP.NET Web API coding interview questions and answers for developers.
More new features introduced in ASP.NET Web API framework v2.0 are as follows:
Attribute Routing
External Authentication
CORS (Cross-Origin Resource Sharing)
OWIN (Open Web Interface for .NET) Self Hosting
IHttpActionResult
Source: codeproject.com
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
Support for OData
Source: codeproject.com
https://github.com/Devinterview-io/asp-net-web-api 3/17
21/09/2021, 12:55 GitHub - Devinterview-io/asp-net-web-api: 🟣 ASP.NET Web API coding interview questions and answers for developers.
Source: career.guru99.com
Basically there are three parties involved: oAuth Provider, oAuth Client and Owner.
Source: stackoverflow.com
Answer:
Use Controller to render your normal views.
ApiController action only return data that is serialized and sent to the client.
Consider:
// GET: /Tweets/
[HttpGet]
or
https://github.com/Devinterview-io/asp-net-web-api 4/17
21/09/2021, 12:55 GitHub - Devinterview-io/asp-net-web-api: 🟣 ASP.NET Web API coding interview questions and answers for developers.
// GET: /Api/Tweets/
return Twitter.GetTweets();
Source: stackoverflow.com
Source: codeproject.com
Answer:
AttributeRouting
OWIN self host
IHttpActionResult
CORS
HttpRequestContext
Betters Testability
ODATA Improvements
Filter Overrides
ByteRangeStreamContent
Source: stackoverflow.com
https://github.com/Devinterview-io/asp-net-web-api 5/17
21/09/2021, 12:55 GitHub - Devinterview-io/asp-net-web-api: 🟣 ASP.NET Web API coding interview questions and answers for developers.
Config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{Controller}/{id}",
);
So, any incoming request is matched against already defined routeTemplate and further
routed to matched controller action. But it’s really hard to support certain URI patterns
using conventional routing approach like nested routes on same controller. For example,
authors have books or customers have orders, students have courses etc.
Such patterns can be defined using attribute routing i.e. adding an attribute to controller
action as follows:
[Route("books/{bookId}/authors")]
Source: webdevelopmenthelp.net
Source: medium.com
Answer:
Although both WCF REST and ASP.NET Web API follows the REST architecture but these
have follow differences:
WCF REST
As compared with WCF REST, Web API supports full features of HTTP.
Its possible to host Web API in IIS as well as in an application.
Source: stackoverflow.com
Answer:
The purpose of Web API framework is to generate HTTP services that reach more
clients by generating data in raw format, for example, plain XML or JSON string. So,
ASP.NET Web API creates simple HTTP services that renders raw data.
On the other hand, ASP.NET MVC framework is used to develop web applications that
generate Views (HTML) as well as data. ASP.NET MVC facilitates in rendering HTML
easy.
Source: codeproject.com
https://github.com/Devinterview-io/asp-net-web-api 7/17
21/09/2021, 12:55 GitHub - Devinterview-io/asp-net-web-api: 🟣 ASP.NET Web API coding interview questions and answers for developers.
If we intended to use transport other than HTTP, e.g. TCP, UDP or Named Pipes
Message Queuing scenario using MSMQ
One-way communication or Duplex communication
Source: codeproject.com
Answer:
Attribute programming plays its role here. We can easily restrict access to an ASP.NET Web
API method to be called using a specific HTTP method. For example, we may require in a
scenario to restrict access to a Web API method through HTTP POST only as follows:
[HttpPost]
StudentRepository.AddStudent(aStudent);
Source: codeproject.com
https://github.com/Devinterview-io/asp-net-web-api 8/17
21/09/2021, 12:55 GitHub - Devinterview-io/asp-net-web-api: 🟣 ASP.NET Web API coding interview questions and answers for developers.
A message handler is a class that receives an HTTP request and returns an HTTP response.
Message handlers derive from the abstract HttpMessageHandler class.
Typically, a series of message handlers are chained together. The first handler receives an
HTTP request, does some processing, and gives the request to the next handler. At some
point, the response is created and goes back up the chain. This pattern is called a delegating
handler.
Consider:
HttpRequestMessage request,
CancellationToken cancellationToken)
// ...
GlobalConfiguration.Configuration
.MessageHandlers
.Add(new DateObsessedHandler());
Source: docs.microsoft.com
https://github.com/Devinterview-io/asp-net-web-api 9/17
21/09/2021, 12:55 GitHub - Devinterview-io/asp-net-web-api: 🟣 ASP.NET Web API coding interview questions and answers for developers.
Source: stackoverflow.com
Answer:
CORS (Cross-origin resource sharing) is a technique that allows restricted resources on a
web page to be requested from another domain outside the domain of which the first
resource was served. A web page may freely attach cross-origin images, scripts, stylesheets,
iframes, and videos. The same-origin security policy by default does not allow certain
“cross-domain” requests, notably Ajax requests.
Cross-origin resource sharing provides a way by which a browser and server can interact to
determine whether allowing the cross-origin requests are safe or not.
Source: webdevelopmenthelp.net
Source: codeproject.com
https://github.com/Devinterview-io/asp-net-web-api 10/17
21/09/2021, 12:55 GitHub - Devinterview-io/asp-net-web-api: 🟣 ASP.NET Web API coding interview questions and answers for developers.
Answer:
No, we can't return a view from ASP.NET Web API method. ASP.NET Web API creates HTTP
services that render raw data. Although, it's quite possible in ASP.NET MVC application.
Source: codeproject.com
GlobalConfiguration.Configuration.Filters.Add(new
MyTestCustomerStore.NotImplExceptionFilterAttribute());
Source: career.guru99.com
ASP.NET Web API 2, support for $expand, $select, and $value options added for OData.
These options simplify to control the representation that is returned from the server.
Source: webdevelopmenthelp.net
https://github.com/Devinterview-io/asp-net-web-api 11/17
21/09/2021, 12:55 GitHub - Devinterview-io/asp-net-web-api: 🟣 ASP.NET Web API coding interview questions and answers for developers.
Answer:
HTTP Module - This is an option for Web APIs running on IIS. HTTP modules allow
security code to execute early as part of the IIS pipeline. The principal established from
an HTTP module is available to all components, including the IIS components running
later in the pipeline.
Message Handler - An extensibility option provided by ASP.NET Web API, the greatest
benefit in using a message handler for security is it’s a concept of the ASP.NET Web API
framework and, hence, doesn’t depend on the underlying host or server. Also, a
message handler runs only for Web API requests. The downside of using a message
handler is the lack of finer control.
The DelegatingHandler is part of the Web API pipeline and can run under any host.
HttpModule is not part of Web Api and requires IIS.
Source: stackoverflow.com
Answer:
ere are several benefits of IHttpActionResult over HttpResponseMessage mentioned in
Microsoft ASP.Net Documentation:
https://github.com/Devinterview-io/asp-net-web-api 12/17
21/09/2021, 12:55 GitHub - Devinterview-io/asp-net-web-api: 🟣 ASP.NET Web API coding interview questions and answers for developers.
Source: stackoverflow.com
Answer:
OWIN (Open Web Interface for .NET) is an interface for .NET between .NET web
applications and web server. It is an open source technology. OWIN aims to decouple the
connection between ASP.NET applications and IIS by giving a standard interface. Developers
of web servers may be sure that, if they implement OWIN properly, ASP.NET applications
can run on their server. Similarly, new web frameworks can be developed as a replacement
to ASP.NET.
Source: webdevelopmenthelp.net
Answer:
Web Service
WCF
https://github.com/Devinterview-io/asp-net-web-api 13/17
21/09/2021, 12:55 GitHub - Devinterview-io/asp-net-web-api: 🟣 ASP.NET Web API coding interview questions and answers for developers.
WCF Rest
Web API
This is the new framework for building HTTP services with easy and simple way.
Web API is open source an ideal platform for building REST-ful services over the .NET
Framework.
Unlike WCF Rest service, it use the full feature of HTTP (like URIs, request/response
headers, caching, versioning, various content formats)
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.
It can be hosted with in the application or on IIS.
It is light weight architecture and good for devices which have limited bandwidth like
smart phones.
Responses are formatted by Web API’s MediaTypeFormatter into JSON, XML or
whatever format you want to add as a MediaTypeFormatter.
Choose WCF when you want to create a service that should support special scenarios
such as one way messaging, message queues, duplex communication etc.
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.
Choose Web API when you want
Source: stackoverflow.com
🔹 29. Could you clarify what is the best practice with Web
API error management?
https://github.com/Devinterview-io/asp-net-web-api 14/17
21/09/2021, 12:55 GitHub - Devinterview-io/asp-net-web-api: 🟣 ASP.NET Web API coding interview questions and answers for developers.
Answer:
README.md
[Route("CheckId/{id}")]
[HttpGet]
};
return Ok(id);
Use Exception Filters to deal with particular unhandled exceptions on multiple actions
and controllers.
[Route("ItemNotFound/{id}")]
[HttpPost]
_service.ThrowItemNotFoundException();
return Ok();
Use Exception Handlers (one per application) to deal with any unhandled exception
application-wide. They called after Exception Filters and Exception Loggers.
https://github.com/Devinterview-io/asp-net-web-api 15/17
21/09/2021, 12:55 GitHub - Devinterview-io/asp-net-web-api: 🟣 ASP.NET Web API coding interview questions and answers for developers.
Source: stackoverflow.com
Answer:
The .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 a lot of articles over the internet
which may describe to whom you should use.
Web Service
WCF
WCF Rest
Web API
This is the new framework for building HTTP services with easy and simple way.
https://github.com/Devinterview-io/asp-net-web-api 16/17
21/09/2021, 12:55 GitHub - Devinterview-io/asp-net-web-api: 🟣 ASP.NET Web API coding interview questions and answers for developers.
Web API is open source an ideal platform for building REST-ful services over the .NET
Framework.
Unlike WCF Rest service, it use the full feature of HTTP (like URIs, request/response
headers, caching, versioning, various content formats)
It also supports the MVC features such as routing, controllers, action results, filter,
model binders, IOC container or dependency injection, unit testing
Source: stackoverflow.com
Thanks 🙌 for reading and good luck on your next tech interview!
Releases
No releases published
Packages
No packages published
https://github.com/Devinterview-io/asp-net-web-api 17/17