.NET Web API Flashcards
What is different between REST API and RESTful API?
REST (Representation State Transfer) API:
It is an architectural style that makes use of existing web technologies and protocols. It is a set of rules that developers need to follow when they develop their API or services that are scalable. It is used with HTTP protocol using its verbs such as GET, DELETE, POST, PUT.
RESTful API:
It is simply referred to as web services executing such as architecture.
What are the advantages of using Rest in Web API?
REST is very important and beneficial in Web API because of the following reasons:
- It allows less data transfer between client and server.
- It is easy to use and lightweight.
- It provides more flexibility.
- It also handles and controls various types of calls, returning various data formats.
- It is considered best for using it in mobile apps because it makes less data transfer between client and server.
- It uses simple HTTP calls for inter-machine communication rather than using more complex options like CORBA, COM+, SOAP, or RPC.*
Web API supports which protocol?
Web API generally supports only HTTP protocol.
What are Web API filters?
Filters are used to add extra logic at different levels of Web API framework request processing.
- Authentication Filter:
- Authorization Filter:
- Action Filter:
- Exception Filter:
- Override Filter:
Who can consume Web API?
It can also be consumed by any client that supports HTTP verbs such as GET, DELETE, POST, PUT.
Web API sends which HTTP response for all uncaught exceptions?
HTTP.500 - INTERNAL SERVER ERROR
What is the difference between ApiController and Controller?
ApiController: It is used to return any type of data to the client.
Controller: Must return ActionResult, typical of Views
What is Caching and what are its types?
Caching is a technique or process of storing data somewhere or in the cache for future requests. The cache is a temporary storage area. Caching keeps all frequently or recently accessed files or data in the cache memory and accesses them from the cache itself rather than actual address of data or files. The cache interface simply improves the storage mechanism for request/response object pairs that are being cached.
- Page Caching
- Data Caching
- Fragment Caching
What is ASP.NET Web API routing?
Routing is a process of mapping requests to the resources that handle the request.
Convention-based routing:
Web API supports convention-based routing. In this type of routing, Web API uses route templates to select which controller and action method to execute.
Attribute-based routing:
Web API 2 generally supports a new type of routing known as attribute routing. As the name suggests, it uses attributes to define routes. It is the ability to add routes to the route table via attributes.
Explain basic ASP.NET Web API security?
Web API can be accessed by anyone who knows the URL. Therefore, it can become a target for hackers. One needs to secure Web API by controlling who can and who cannot have access to Web API.
Authentication:
It is a process that helps to identify and check users by their credentials such as password, username, etc. To have access to the web API, firstly user credentials are needed to be passed in the request (authorization) header in the form of user/pass or bearer token. If user credentials are not passed into the request header, then the server returns 401 status code (unauthorized). The most popular authentication scheme is OAuth 2.0.
Authorization:
It is a process that helps to decide whether or not a user has access to perform an action. Authorization filters are used to implement authorization.
What is the difference between OAuth2 and JWT?
OAuth 2.0 is a protocol, e.g. specifies how tokens are transferred whereas JWT is a token format. OAuth can, and often does use JWT as its token format.
JSON Web Token:
* a JWT is a JSON based security token format which is a base64 url-encoded string used as a means of transferring secure content between two applications. They are used to secure request data in Web APIs. These are included in Authorization HTTP headers as part of the bearer authentication scheme.
- A JWT token is composed of a header, a payload, and a signature and has the format: header.payload.signature
- A JWT is digital signed by the server to it cannot be manipulated by clients or middleware
- The client should not store the bearer token inside localstorage as this would expose the token to any script running on the client. The client should implement an HttpOnly cookie
OAuth2:
* OAuth is not an API or a service: it’s an open standard for authorization that anyone can implement
- OAuth is a standard that apps can use to provide client applications with “secure delegated access”. In other words, its a way to allow users to login using 3rd party credentials (facebook, Google, etc) without giving those 3rd parties your password. OAuth works over HTTPS and authorizes devices, APIs, servers, and applications with access tokens rather than credentials.
What are Exception filters in ASP.NET Web API?
Exception filter is generally used to handle all unhandled exceptions that are generated in web API. It implements IExceptionFilters interface. It is the easiest and most flexible to implement. This filter is executed whenever the controller method throws any unhandled exception at any stage that is not an HttpResponseExecption exception.
What are the Http verbs?
POST: Create new record; returns 201, 409 (conflict), or 404 (not found)
GET: Read; large lists, pagination, sorting; returns 200 (Ok), 404 (not found or invalid id)
PUT: Update/Replace; returns 405 (not allowed), 200 (Ok), 204 (no content), 404 (not found or invalid id)
PATCH: Update/Modify: returns 405 (not allowed), 200 (Ok), 204 (no content), 404 (not found or invalid id)
DELETE: Delete: returns 405 (not allowed), 200 (Ok), 404 (not found or invalid id)
What is CORS in Web API?
CORS (Cross-Origin Resource Sharing) is a mechanism that allows one to make requests from one website to another website in a browser that is normally not allowed by another policy called SOP (Same Origin Policy). It supports secure cross-origin requests and data transfers among clients or browsers and servers. Here, cross-origin request means requests coming from different origins. CORS simply resolves the same-origin restriction for JavaScript.
Explain the Http Lifecycle from end to end
- You initiate a connection specifying a url to connect to
- An HTTP Request is created that contains a verb and a path and a set of custom headers like authorization (bearer token).
- The Request is sent to the Server
- The Server reads the Request and takes action based on the verb, path, and header data received
- The Server generates an HTTP Response to the Request.
- The server sends the Response back to the client browser.
- Your client receives and processes response as dictated by the application.