API Flashcards
What is the purpose of an API?
APIs facilitate communication between different software applications, enabling them to interact, exchange data, or access functionalities.
What are the common types of APIs?
Common types include Web APIs (utilized over the internet), Library-Based APIs (functions within programming libraries), and Operating System APIs (interaction with operating system functions).
How do APIs ensure security?
APIs often employ authentication methods such as API keys, OAuth, or tokens to secure access to data or services.
What benefits do APIs offer in software development?
APIs promote interoperability, integration between systems, and boost development efficiency by leveraging existing functionalities.
Dispatcher Servlet
Central servlet in the Spring MVC framework that receives incoming requests and directs them to the appropriate controllers for processing.
Initialization
During application startup, the Dispatcher Servlet is initialized by the Spring container and configured based on application settings.
Request Handling
When a request comes in, the Dispatcher Servlet maps it to the appropriate handler (controller) based on the request URL using handler mappings.
Handler Mapping
Configured components within the Dispatcher Servlet that determine which controller should handle an incoming request based on URL patterns or other criteria.
View Resolution
Once the controller processes the request, the Dispatcher Servlet identifies the correct view (often a JSP, Thymeleaf, or HTML file) to render the response.
Response Handling
The Dispatcher Servlet takes the view returned by the controller and generates the response to be sent back to the client.
@Controller
An annotation used in Spring MVC to denote a class as a controller. It handles HTTP requests and typically returns data to the view layer.
@RestController
A specialized version of the @Controller annotation in Spring MVC that combines @Controller and @ResponseBody. It’s used for RESTful APIs, automatically serializing data to JSON or XML and returning it in the response body.
AbstractController
A base controller class in Spring MVC that provides common functionalities like request handling methods and view handling. Developers can extend this class to create custom controllers.
HandlerInterceptor
Not exactly a controller, but it’s a mechanism provided by Spring MVC to intercept requests before or after they reach the controller. It’s useful for logging, authorization, or modifying requests.
@RequestMapping
An annotation used to map HTTP requests to specific handler methods within a controller class. It allows defining URL patterns and HTTP methods that a controller method can handle.
RestControllerAdvice
An annotation used to define a global advice for REST controllers. It can handle exceptions, apply common processing, or perform actions before or after controller methods.
Resource
Any information that can be named and represented as a URL. It could be an object, data, or service that the API deals with.
Stateless
Each request from the client to the server must contain all the necessary information for the server to understand and process it, without relying on previous interactions.
URI (Uniform Resource Identifier)
A string of characters that identifies a particular resource. In REST, URIs are used to locate and interact with resources.
HATEOAS (Hypermedia as the Engine of Application State)
A principle in RESTful APIs where responses include links to related resources, enabling clients to navigate the API dynamically.
Content Negotiation
The process of determining the best response format (JSON, XML, etc.) based on the client’s requested media type sent in the request headers.
PUT PATCH differences
Stateful Protocols:
TCP (Transmission Control Protocol): Although it’s connection-oriented, TCP itself is stateful, maintaining information about the connection between two endpoints.
FTP (File Transfer Protocol): FTP sessions maintain state, remembering the client’s current directory, authentication details, and more across interactions.
WebSockets: While HTTP is stateless, WebSockets are stateful, allowing continuous bidirectional communication after the initial connection establishment.
Stateless Protocols
HTTP (Hypertext Transfer Protocol): The classic web communication protocol is stateless by design. Each HTTP request from a client to a server stands alone and contains all necessary information for processing that request.
UDP (User Datagram Protocol): It’s a connectionless and stateless protocol used for lightweight and low-latency communication. Each UDP packet is independent and does not rely on prior packets.