The Journey of an API Call: From Angular to Spring Boot
Alright, let’s dive deep into each step of the process from an Angular application making a GET API call to a Spring Boot backend, covering everything from DNS resolution to the response being displayed on the Angular UI. I'll cover the entire flow with as much detail as possible.
1. Angular Makes an API Request
-> Using the HttpClient Library:
this.httpClient.get('https://indepthcoding.com/rest/getAllUsers');
-> Creating the HTTP Request:
2. DNS Resolution
-> Breaking Down the URL:
-> How DNS Works:
i. Local Cache: If it knows the IP.
ii. Root DNS Server: If needed, it asks the root server where to find .com domains.
iii. TLD Server: The .com server directs it to the authoritative DNS server for indepthcoding.com.
iv. Authoritative Server: Returns the IP address for indepthcoding.com.
3. Establishing a Connection
-> TCP/IP Connection:
i. SYN: The browser sends a SYN packet to the server.
ii. SYN-ACK: The server responds with a SYN-ACK.
iii. ACK: The browser sends an ACK, and the connection is established.
-> HTTPS Connection (TLS Handshake):
i. Client Hello: The browser sends supported encryption algorithms to the server.
ii. Server Hello: The server responds with a chosen encryption algorithm and its SSL certificate.
iii. Certificate Verification: The browser verifies the server’s certificate against trusted CAs.
iv. Key Exchange: Both the browser and server exchange keys to establish a secure session.
v. Finished: A secure encrypted connection is now established.
4. Sending the HTTP Request
-> Browser Sends the GET Request
GET /rest/getAllUsers HTTP/1.1
Host: indepthcoding.com
Accept: application/json
5. Tomcat (Servlet Container) Receives the Request
-> Tomcat’s Role:
->Mapping to the Servlet:
6. DispatcherServlet Handles the Request
-> Finding the Controller:
领英推荐
-> Dependency Injection (DI):
-> Controller Method Execution:
7. Repository Accesses the Database
-> Database Connection Management:
-> Executing a Query:
List<User> findAll();
SELECT * FROM users;
-> Mapping Results:
8. Returning the Response
-> Controller Returns Data:
-> DispatcherServlet Prepares the Response:
9. Tomcat Sends the Response
-> Packaging the HTTP Response:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: <length>
[ { "id": 1, "name": "Pratyush Raj" }, ... ]
-> Sending Back Over the Secure Connection:
10. Browser Receives the Response
-> Decryption and Parsing:
-> HttpClient Resolves the Promise:
11. Displaying the Data on the UI
-> Binding the Data:
-> Rendering on the Screen:
This process involves several layers, from DNS resolution and HTTP requests to the internal workings of Spring Boot, including Tomcat, DispatcherServlet, Dependency Injection, database access, and the final delivery of the response to the Angular application. Each step is crucial for the successful retrieval and display of data on the client-side.