API Flashcards

1
Q

What is the purpose of an API?

A

APIs facilitate communication between different software applications, enabling them to interact, exchange data, or access functionalities.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the common types of APIs?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do APIs ensure security?

A

APIs often employ authentication methods such as API keys, OAuth, or tokens to secure access to data or services.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What benefits do APIs offer in software development?

A

APIs promote interoperability, integration between systems, and boost development efficiency by leveraging existing functionalities.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Dispatcher Servlet

A

Central servlet in the Spring MVC framework that receives incoming requests and directs them to the appropriate controllers for processing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Initialization

A

During application startup, the Dispatcher Servlet is initialized by the Spring container and configured based on application settings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Request Handling

A

When a request comes in, the Dispatcher Servlet maps it to the appropriate handler (controller) based on the request URL using handler mappings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Handler Mapping

A

Configured components within the Dispatcher Servlet that determine which controller should handle an incoming request based on URL patterns or other criteria.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

View Resolution

A

Once the controller processes the request, the Dispatcher Servlet identifies the correct view (often a JSP, Thymeleaf, or HTML file) to render the response.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Response Handling

A

The Dispatcher Servlet takes the view returned by the controller and generates the response to be sent back to the client.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

@Controller

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

@RestController

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

AbstractController

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

HandlerInterceptor

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

@RequestMapping

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

RestControllerAdvice

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Resource

A

Any information that can be named and represented as a URL. It could be an object, data, or service that the API deals with.

18
Q

Stateless

A

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.

19
Q

URI (Uniform Resource Identifier)

A

A string of characters that identifies a particular resource. In REST, URIs are used to locate and interact with resources.

20
Q

HATEOAS (Hypermedia as the Engine of Application State)

A

A principle in RESTful APIs where responses include links to related resources, enabling clients to navigate the API dynamically.

21
Q

Content Negotiation

A

The process of determining the best response format (JSON, XML, etc.) based on the client’s requested media type sent in the request headers.

22
Q

PUT PATCH differences

A
23
Q

Stateful Protocols:

A

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.

24
Q

Stateless Protocols

A

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.

25
Q

1-1 connection protocols

A

TCP (Transmission Control Protocol):
1-1 Relationship: TCP establishes a reliable, connection-oriented communication between two hosts. Each TCP connection is uniquely identified by a combination of IP addresses and port numbers, creating a 1-1 relationship.
Usage: TCP is widely used in various applications requiring reliable and ordered delivery of data, such as web browsing, email, file transfer, etc.
UDP (User Datagram Protocol):
1-1 Relationship: While UDP is connectionless and does not maintain a connection like TCP, each UDP packet is still sent from one sender to a specific receiver, establishing a 1-1 relationship for each packet.
Usage: UDP is used in scenarios where low-latency and quick data transmission are crucial, such as real-time streaming, online gaming, DNS, etc.
FTP (File Transfer Protocol):
Control Connection: As mentioned earlier, FTP establishes a control connection between a client and a server for managing commands and session information. It follows a 1-1 relationship for the control connection.
Data Connection(s): Each data connection in FTP, whether in active or passive mode, establishes a 1-1 relationship between the client and server for transferring file data.
SSH (Secure Shell):
1-1 Relationship: SSH allows secure, encrypted communication between two networked devices. Each SSH session establishes a 1-1 encrypted connection, ensuring confidentiality and integrity between the client and server.

26
Q

Multicast protocols

A

UDP (User Datagram Protocol) Multicast:
1-n Relationship: UDP multicast enables one-to-many communication, allowing a sender to transmit a single packet to multiple recipients simultaneously.
Usage: Multicast is used for streaming multimedia content, live video broadcasts, online conferences, and applications where data needs to be delivered to multiple recipients efficiently.
IGMP (Internet Group Management Protocol):
1-n Relationship: IGMP works in conjunction with multicast protocols, allowing hosts to join or leave multicast groups. It enables efficient communication between one sender and multiple receivers within a multicast group.
Usage: IGMP assists in managing multicast traffic and enabling hosts to subscribe to or unsubscribe from multicast groups.
HTTP Server-Sent Events (SSE):
1-n Relationship: SSE allows servers to push real-time updates or messages to multiple clients simultaneously over a single HTTP connection.
Usage: SSE is used for streaming updates, notifications, or real-time data to web applications without the need for continuous client requests.
IP (Internet Protocol) Broadcasting:
1-n Relationship: IP broadcasting allows one sender to transmit data packets to all devices within a specific broadcast domain or subnet.
Usage: Broadcasting is utilized for sending messages or data to all devices within a network segment, such as DHCP (Dynamic Host Configuration Protocol) requests, ARP (Address Resolution Protocol) queries, etc.

27
Q

What is a chatty API?

A

A chatty API refers to an interface that requires a high number of small, frequent, or unnecessary requests between a client and a server to accomplish tasks or retrieve data. This results in inefficiencies and increased network traffic.

28
Q

What strategies can mitigate chatty APIs?

A

Strategies include batching or aggregation of requests, caching frequently requested data, using pagination to limit data retrieval, and optimizing endpoints to reduce unnecessary communication.

29
Q

What characterizes a chatty API?

A

Chatty APIs involve high request frequency, small payloads, overuse of resources, and increased latency due to excessive back-and-forth communication between the client and server.

30
Q

What is type erasure?

A

Type erasure is a process in programming languages like Java where the compiler removes the type information associated with generic types during compilation.

31
Q

Which languages commonly use type erasure?

A

Type erasure is notably used in Java, among other languages that support generics, to maintain backward compatibility with older versions of the language.

32
Q

When does type erasure occur in Java?

A

Type erasure takes place during the compilation process in Java. The compiler replaces generic types with their raw types and removes the type parameters.

33
Q

What happens to generic type information after type erasure?

A

After type erasure, the specific generic type information is not available at runtime. Instead, the code typically operates on the raw types and uses type casting where necessary.

34
Q

What is RestTemplate?

A

RestTemplate is a class in Spring that provides a synchronous way to make HTTP requests to external RESTful services. It simplifies communication with RESTful APIs by abstracting the complexities of making HTTP requests and handling responses.

35
Q

How does RestTemplate handle HTTP requests?

A

RestTemplate handles HTTP requests by providing methods that correspond to different HTTP methods (GET, POST, PUT, DELETE, etc.). It offers various functionalities like handling request headers, response mapping, and error handling, simplifying interactions with RESTful APIs in Java applications.

36
Q

What are the differences between RestTemplate and WebClient in Spring?

A

RestTemplate:
Synchronous: Executes requests in a blocking manner.
Deprecated: Deprecated since Spring 5.0 in favor of WebClient.
Thread Usage: Uses a separate thread for each request.
Response Mapping: Maps responses using MessageConverters.
Functionality: Provides a more traditional, imperative-style API.
Flexibility: Limited non-blocking I/O support.
WebClient:
Asynchronous: Provides non-blocking I/O for reactive applications.
Replacement: Introduced as a replacement for RestTemplate.
Thread Usage: Utilizes fewer threads, suitable for highly concurrent applications.
Response Mapping: Utilizes reactive streams for mapping responses.
Functionality: Embraces a more functional, reactive-style API.
Flexibility: Offers better support for non-blocking scenarios and reactive programming paradigms in Spring.

37
Q

What are the key differences between RestTemplate and WebClient?

A

RestTemplate is a synchronous client for making HTTP requests in Spring, relying on blocking I/O. It’s part of the Spring framework and uses HTTP connections from a connection pool. WebClient, on the other hand, is a reactive, non-blocking, and more modern alternative introduced in Spring WebFlux. It’s based on Reactor and is designed to handle asynchronous communication using a reactive programming model, which can improve performance in handling concurrent requests. WebClient supports both synchronous and asynchronous operations and is suitable for building reactive applications.

38
Q

What is Eureka in the context of microservices?

A

Eureka is a service discovery tool designed by Netflix to manage and locate services in a microservices architecture.

39
Q

How does Eureka facilitate service discovery?

A

Eureka operates as a service registry where microservices can register themselves and discover other services using a REST-based API.

40
Q

What role does Eureka play in the microservices ecosystem?

A

Eureka acts as a service registry, enabling services to register their location and health status, allowing other services to find and communicate with them.

41
Q

How does Eureka support high availability?

A

Eureka uses a peer-to-peer architecture, where multiple Eureka servers replicate registry information, ensuring resilience and high availability.

42
Q

What benefits does Eureka provide in a microservices setup?

A

Eureka promotes dynamic scaling, fault tolerance, and load balancing by allowing services to discover and communicate with each other seamlessly.