# Business Logic — Example.syncGet() [12 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `io.github.biezhi.java11.http.Example` |
| Layer | Utility (Java 11 HTTP Client demonstration) |
| Module | `http` (Package: `io.github.biezhi.java11.http`) |

## 1. Role

### Example.syncGet()

The `syncGet` method is a synchronous HTTP GET client implementation using Java 11's `HttpClient` API (JEP 321). It performs a blocking HTTP request to a given URI, waits for the complete response, and writes the response status code and body to standard output. The method encapsulates the full request-response lifecycle — creating an `HttpClient` instance, building an `HttpRequest` with the specified URI, sending the request synchronously via `client.send()`, and extracting both the HTTP status code and the response body text. It serves as a standalone utility for making simple synchronous HTTP GET calls and is intended for demonstration purposes within the `java11.http` package. The Javadoc comment "同步调用 GET" (Synchronous call GET) confirms its purpose as a blocking HTTP client wrapper.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["syncGet(uri)"])
    STEP1(["Create HttpClient via HttpClient.newHttpClient()"])
    STEP2(["Build HttpRequest via HttpRequest.newBuilder()"])
    STEP3(["Set URI via URI.create(uri)"])
    STEP4(["Call request.build()"])
    STEP5(["Send request via client.send(request, HttpResponse.BodyHandlers.ofString())"])
    STEP6(["Extract response status code and body"])
    STEP7(["Print response.statusCode() to stdout"])
    STEP8(["Print response.body() to stdout"])
    END(["Return void"])

    START --> STEP1 --> STEP2 --> STEP3 --> STEP4 --> STEP5 --> STEP6 --> STEP7 --> STEP8 --> END
```

The method follows a straightforward linear processing pattern with no conditional branches or loops:

1. **HttpClient Creation** — A new `HttpClient` instance is created via `HttpClient.newHttpClient()`, which provides a default (non-pooled, non-configured) HTTP client using the DEFAULT dispatchers and no proxy settings.
2. **HttpRequest Building** — An `HttpRequest.Builder` is obtained via `HttpRequest.newBuilder()`, then the request URI is set using `URI.create(uri)`, and the request is finalized with `.build()`.
3. **Synchronous Request Dispatch** — The request is sent via `client.send(request, HttpResponse.BodyHandlers.ofString())`, which blocks until the full response (including body) is received. The response body is decoded as a UTF-8 string.
4. **Response Logging** — The HTTP status code (e.g., 200, 404, 500) and the full response body are printed to `System.out` using `System.out.println()`.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `uri` | `String` | The target URI to send the HTTP GET request to. Represents a complete Uniform Resource Identifier (e.g., `"https://example.com/api/data"`). The method delegates to `URI.create(uri)` which parses the string into a `java.net.URI` object, so it must be a valid URI string (including scheme, host, and optionally path/port/query). |

**External State / Instance Fields:** None — this is a static method with no instance field dependencies.

**Throws:** `Exception` — The method declares a generic `Exception` throw, which may surface as `IOException` (network errors), `InterruptedException` (thread interruption during the blocking call), or `IllegalArgumentException` (invalid URI).

## 4. CRUD Operations / Called Services

This method performs network I/O rather than database or SC-level CRUD operations. It is a pure HTTP client wrapper.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| N/A | `HttpClient.newHttpClient()` | N/A | N/A | Creates a new HTTP client instance for outbound network requests. |
| N/A | `HttpRequest.newBuilder()` | N/A | N/A | Creates an HTTP request builder for constructing the GET request. |
| N/A | `URI.create(uri)` | N/A | N/A | Parses the string URI into a `java.net.URI` object. |
| N/A | `client.send(request, ...)` | N/A | N/A | Sends the HTTP GET request and waits for a synchronous response (blocking I/O). |
| N/A | `System.out.println(...)` | N/A | N/A | Writes the HTTP status code and response body to standard output (logging). |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | N/A (Commented-out example) | `Example.syncGet("https://biezhi.me")` | N/A — no downstream service calls |

The only reference to `syncGet` is within commented-out code (lines 189-190) in the same `Example` class, where it is invoked as a standalone example with the URL `"https://biezhi.me"`. There are no active callers in the codebase.

## 6. Per-Branch Detail Blocks

This method has no conditional branches, loops, or exception handlers. It follows a single linear execution path.

**Block 1** — [SEQUENTIAL EXECUTION] `(no condition)` (L29)

No branching logic exists. The entire method is a flat sequence of 5 key operations:

| # | Type | Code |
|---|------|------|
| 1 | SET | `HttpClient client = HttpClient.newHttpClient();` // Create a new HTTP client with default settings [L30] |
| 2 | SET | `HttpRequest request = HttpRequest.newBuilder().uri(URI.create(uri)).build();` // Build and finalize HTTP GET request with the given URI [L31-L33] |
| 3 | SET | `HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());` // Send request synchronously, block until full response received, body decoded as UTF-8 string [L35-L36] |
| 4 | EXEC | `System.out.println(response.statusCode());` // Print HTTP status code (e.g., 200, 404) to stdout [L38] |
| 5 | EXEC | `System.out.println(response.body());` // Print HTTP response body to stdout [L39] |

No else blocks, no catch blocks, no fallback paths. The method terminates after printing the response.

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `syncGet` | Method | Synchronous HTTP GET — a blocking web request method that waits for the full response before returning |
| `uri` | Parameter | Uniform Resource Identifier — the target URL of the HTTP GET request |
| `HttpClient` | Class | Java 11 HTTP Client (JEP 321) — the standard library HTTP client for making HTTP requests |
| `HttpRequest` | Class | Java 11 HTTP Request representation — builder-based object defining the HTTP request (method, URI, headers, body) |
| `HttpResponse` | Class | Java 11 HTTP Response representation — contains the status code, headers, and body from the HTTP response |
| `newHttpClient()` | Method | Factory method that creates a new default `HttpClient` instance |
| `BodyHandlers.ofString()` | Method | Response body handler that decodes the response body as a UTF-8 String |
| `同步调用 GET` | Comment | "Synchronous call GET" — Japanese comment describing the blocking nature of the method |
| `System.out` | Field | Standard output stream — used to print the response status code and body for debugging/demo purposes |
