---
# (DD08) Business Logic — CurrencyRateAPI.getApiKeyService() [14 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.github.blaxk3.api.CurrencyRateAPI` |
| Layer | Utility |
| Module | `api` (Package: `com.github.blaxk3.api`) |

## 1. Role

### CurrencyRateAPI.getApiKeyService()

This method is the configuration access point for the currency-rate integration layer. Its business responsibility is to retrieve the external API credential from the application runtime configuration and return it as a plain `String`, so that downstream URL construction can authenticate requests to the exchange-rate provider. In operational terms, it acts as a lightweight secret resolver rather than a transformation or calculation method.

The method follows a simple routing/lookup pattern: it opens the classpath resource `config.properties`, loads key-value pairs, and extracts the `API_KEY` entry. If the resource cannot be found or if configuration loading fails, the method logs the problem and returns `null`, allowing the caller to detect a missing credential and fail safely. This makes the method a shared utility for the API client construction path, especially the `getURL()` method that prefixes the base endpoint with the resolved key. The method has no branching by business service type; instead, it has two failure branches around configuration availability and I/O reliability.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["getApiKeyService()"])
    CREATE(["Create Properties instance"])
    OPEN(["Load config.properties from classpath"])
    CHECK{"InputStream is null?"}
    LOG_MISSING(["Log error - Unable to find config.properties"])
    RETURN_NULL1(["Return null"])
    LOAD(["Load properties from InputStream"])
    GET_KEY(["Read API_KEY from properties"])
    RETURN_KEY(["Return API_KEY value"])
    CATCH(["Catch IOException"])
    LOG_IO(["Log error - Error loading config.properties"])
    RETURN_NULL2(["Return null"])
    END(["End"])

    START --> CREATE
    CREATE --> OPEN
    OPEN --> CHECK
    CHECK -- "Yes" --> LOG_MISSING
    LOG_MISSING --> RETURN_NULL1
    CHECK -- "No" --> LOAD
    LOAD --> GET_KEY
    GET_KEY --> RETURN_KEY
    RETURN_KEY --> END
    OPEN --> CATCH
    CATCH --> LOG_IO
    LOG_IO --> RETURN_NULL2
    RETURN_NULL2 --> END
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | - |

External state read by the method:
- `config.properties` on the application classpath — source of the external API credential.
- `API_KEY` property value — authentication token used to compose the external exchange-rate request URL.
- `logger` — records configuration and I/O failures for operational diagnostics.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `getResourceAsStream` | - | `config.properties` | Reads the application configuration resource from the classpath to resolve the API credential. |
| R | `Properties.load` | - | `config.properties` | Loads key-value pairs from the configuration stream into memory. |
| R | `Properties.getProperty` | - | `API_KEY` | Reads the stored API key value used to authenticate the currency-rate request. |

Notes:
- This method does not call any business SC/CBS service or database CRUD endpoint.
- Its only data access is read-only configuration access from the classpath resource.

## 5. Dependency Trace

### Pre-computed evidence from code analysis graph:

| # | Caller (Screen/Batch) | Call Chain (Full Path to Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|----------------------------------|-------------------------------|
| 1 | Controller:CurrencyRateAPI | `CurrencyRateAPI.getURL` -> `CurrencyRateAPI.getApiKeyService` | `getApiKeyService [R] config.properties` |

Trace who calls this method and what this method ultimately calls.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Controller:CurrencyRateAPI | `CurrencyRateAPI.getURL` -> `CurrencyRateAPI.getApiKeyService` | `getResourceAsStream [R] config.properties` |
| 2 | Controller:CurrencyRateAPI | `CurrencyRateAPI.getURL` -> `CurrencyRateAPI.getApiKeyService` | `Properties.load [R] config.properties` |
| 3 | Controller:CurrencyRateAPI | `CurrencyRateAPI.getURL` -> `CurrencyRateAPI.getApiKeyService` | `Properties.getProperty [R] API_KEY` |

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENCE] `(method entry)` (L23)

> Initializes the configuration lookup flow for the external exchange-rate API.

| # | Type | Code |
|---|------|------|
| 1 | SET | `Properties properties = new Properties();` |

**Block 2** — [TRY] `(load config.properties from classpath)` (L24-L25)

> Opens the classpath resource that contains the external API credential.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `getClass().getClassLoader().getResourceAsStream("config.properties")` |
| 2 | SET | `InputStream input = ...` |

**Block 2.1** — [IF] `(input == null)` (L26)

> Handles the case where the configuration resource is missing from the runtime classpath.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `logger.error("Unable to find config.properties");` |
| 2 | RETURN | `return null;` |

**Block 2.2** — [ELSE] `(input != null)` (implicit) (L29-L30)

> Loads the credential from the property file and returns the key for URL construction.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `properties.load(input);` |
| 2 | RETURN | `return properties.getProperty("API_KEY");` |

**Block 3** — [CATCH] `(IOException e)` (L31-L34)

> Handles failures while reading or parsing the property resource.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `logger.error("Error loading config.properties", e);` |
| 2 | RETURN | `return null;` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `config.properties` | Resource | Application configuration file on the classpath that stores runtime settings such as the external API key. |
| `API_KEY` | Config key | Secret value used to authenticate requests to the external exchange-rate service. |
| `logger` | Technical component | Logging facility used to record missing configuration and I/O errors for operations support. |
| `InputStream` | Technical type | Stream used to read the configuration resource bytes from the classpath. |
| `Properties` | Technical type | In-memory key-value container used to load and access configuration entries. |
| classpath | Technical term | Runtime search path where packaged application resources are located. |
| exchange-rate API | Business term | External service that provides currency conversion and exchange-rate data. |
| API | Acronym | Application Programming Interface — external system endpoint accessed by the application. |
