Web API Basics
In the description box, you can find a list of all the questions related to the topic of Web API. The initial focus is on basic questions about Web API. Here is the list of basic questions about Web API, with an approximate duration of 16 to 20 minutes.
Let’s start with the first question: What is Web API, and what is its purpose?
Web API, where “API” stands for Application Programming Interface, provides interaction between software applications. It serves as an intermediary for communication between different software applications. For instance, when placing an order on Amazon via a mobile app or website, the business logic is written in a common Web API, ensuring consistent functionality for various platforms.
Advantages of Web API over WCF and Web Services:
HTTP Works: Web API functions in the same way as HTTP, using HTTP methods like GET, POST, PUT, and DELETE.
Open Source: Web API is open source, unlike WCF (Windows Communication Foundation).
Lightweight Architecture: Web API is lightweight and suitable for devices with limited bandwidth.
Controller Pattern: Web API’s controller pattern is similar to MVC (Model-View-Controller), making it easy to maintain and understand.
Easy Configuration: Web API offers simpler configuration settings compared to WCF.
Token-Based Authentication and JWT in Web APIs:
Token-based authentication is a process where a token is used to verify the authenticity of a client’s request.
JSON Web Token (JWT) is a widely used token format for authentication. It consists of three parts: Header, Payload, and Signature.
REST and RESTful Services:
REST (Representational State Transfer) is a set of guidelines for creating systems where applications can communicate with each other using simple HTTP methods.
RESTful services follow these guidelines, enabling applications to interact efficiently.
Consuming Web API from a .NET MVC Application:
Web API methods can be consumed using the HttpClient class.
The HttpClient class is used to create requests and receive responses from the Web API.
Content Negotiation:
Content negotiation determines the format in which data is sent and received between the client and the Web API.
It allows clients and servers to agree on the representation format (JSON, XML, etc.) for data exchange.
JWT Authentication:
JWT (JSON Web Token) is a token format used for authentication and authorization in Web APIs.
JWT authentication involves exchanging tokens between clients and servers to verify user identity.
Media Type Formatters:
Media type formatters are classes used to serialize and deserialize data between HTTP requests and responses.
They handle the conversion of data between different formats, such as JSON and XML.
HTTP Response Codes:
HTTP response codes indicate the status of a client’s request and the server’s response.
Response codes include informational, success, redirection, client error, and server error codes.