YouTube Interview Questions Flashcards
What is REST?
REST stands for REpresentation State Transfer.
Server responds to Create Read Update and Delete request.
All server endpoints will be an access point to a resource.
This pattern treats every service as a reource and we can access the reourse using CRUD.
What is ASP.NET Web API?
Its is a framework used to develop HTTP based API.
What is a RESTFul service?
It is a pattern to develop a HTTP API.
It should follow:
Client- sevrer isolation. Stateless Cacheable Uniform Interface. Code-on-Demand. Layered architecture.
What are the advantages of using ASP.NET Web API?
TB
What is CORS?
We host a web API in a server, and Browser security prevents a web page from making requests to a different domain than the one that served the web page. This restriction is called the same-origin policy. The same-origin policy prevents a malicious site from reading sensitive data from another site.
To Enable CORS we have to configure it in service.AddCORS();
What is routing?
When a request arrives from a client (browser or any application) arrives to our application, it is the controller which responds to the request. The incoming URL is mapped to the action method. This mapping is done by the routing rules defined by our application.
For example, www.testurl.info/order/1
order is mapped to the controller and 1 is mapped to the id.
In conventional routing, the application uses route template which is defined in the configuration in the middleware.
But in attribute routing, we use Route attribute. this can be applied to either action method or controller.
We can also use token in attribute routing :
[Route(“[controller]/[action]”)]
the Index method templates must prepend / or ~/ to the route templates. Route templates applied to an action that begin with / or ~/ don’t get combined with route templates applied to the controller.
What is Async Controllers?
WHen a request comes to the
What are Action filters?
Action filter allows us to execute custom code either just before the action method is executed or after the action method is executed.
There are 4 types of action filter:
a. Authorization Filter: Implements IAuthorizeFilter. This filter executes before any other filter. We use [Authorize] attribute.
b. Action Filters: Implements IActionFilter. We have to override OnActionExecuting() and OnActionExecuted().
c. Result Filter: Implements IResultFilter. On ResultExecuting and OnResultExecuted().
d. Exception filter: Implements IExceptionFilter. Overrides OnException method .
What is HTTPResponseMessage and IHTTPActionResult?
HTTPResponseMessage was introduced in web APiI 1 and IHTTPActionResult was introduced in Web API 2. The later one provide code readability.
Example:
HTTPResponseMessage Get() { //error
Request.CreateErrorResponse(HttpStatusCode.NotFound, “Student Not found)”
return Request.CreateResponse(HTTPStatusCode.OK, STudent);
}
IHttpActionResult Get() { //error
return NotFound();
or//
Content(HttpStatucCOde.NotFound, “not found”);
return Ok(STudent); }
How can we restrict access to methods with specific HTTP verbs
use attribute such as
[HttpPost]
void Post(Student stu) {}