You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(README): update documentation on success responses, error handling, and request tracing
- Add information about standardized success responses and error handling
- Include details on request traceability using unique request IDs
- Update architecture section with new packages and shared core components
- Revise API endpoint documentation to reflect standard response structure
- Remove redundant error handling information
Copy file name to clipboardExpand all lines: README.md
+34-8Lines changed: 34 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,9 @@
18
18
*`category`
19
19
*`source`
20
20
*`country`
21
+
***Standardized Success Responses:** Returns consistent JSON success responses wrapped in a `SuccessApiResponse` structure, including request metadata (`requestId`, `timestamp`).
22
+
***Standardized Error Handling:** Returns consistent JSON error responses via centralized middleware (`lib/src/middlewares/error_handler.dart`) for predictable client-side handling.
23
+
***Request Traceability:** Generates a unique `requestId` (UUID v4) for each incoming request, included in success response metadata and available for server-side logging via context.
21
24
***In-Memory Demo Mode:** Utilizes pre-loaded fixture data (`lib/src/fixtures/`) for demonstration and development purposes, simulating a live backend without external dependencies.
22
25
***Standardized Error Handling:** Returns consistent JSON error responses via centralized middleware (`lib/src/middlewares/error_handler.dart`) for predictable client-side handling.
23
26
@@ -28,16 +31,17 @@
28
31
***Architecture:** Layered architecture leveraging shared packages and a generic API pattern.
29
32
***Key Packages & Shared Core:**
30
33
*`dart_frog`: The web framework foundation.
31
-
*`ht_shared`: Contains shared data models (`Headline`, `Category`, `Source`, `Country`, etc.) used across the HT ecosystem.
34
+
*`uuid`: Used to generate unique request IDs.
35
+
*`ht_shared`: Contains shared data models (`Headline`, `Category`, `Source`, `Country`, `SuccessApiResponse`, `ResponseMetadata`, etc.) used across the HT ecosystem.
32
36
*`ht_data_client`: Defines the generic `HtDataClient<T>` interface for data access operations.
33
37
*`ht_data_inmemory`: Provides the `HtDataInMemoryClient<T>` implementation, used here for the demo mode, seeded with fixture data.
34
38
*`ht_data_repository`: Defines the generic `HtDataRepository<T>` which abstracts the data client, providing a clean interface to the API route handlers.
35
39
*`ht_http_client`: Provides custom HTTP exceptions (`HtHttpException` subtypes) used for consistent error signaling, even by the in-memory client.
36
40
***Key Patterns:**
37
41
***Generic Repository Pattern:**`HtDataRepository<T>` provides a type-safe abstraction over data fetching logic. Route handlers interact with repositories, not directly with data clients.
38
42
***Generic Data Endpoint:** A single set of route handlers (`/api/v1/data/index.dart`, `/api/v1/data/[id].dart`) serves multiple data models.
39
-
***Model Registry:** A central map (`lib/src/registry/model_registry.dart`) links model name strings (from the `?model=` query parameter) to model-specific configurations (`ModelConfig`), primarily containing serialization/deserialization functions (`fromJson`, `toJson`) and ID extraction logic (`getId`).
40
-
***Dependency Injection (Dart Frog Providers):** Middleware (`routes/_middleware.dart`) is used to instantiate and provide singleton instances of each `HtDataRepository<T>` (configured with the in-memory client and fixture data) and the `ModelRegistryMap`. Route-specific middleware (`routes/api/v1/data/_middleware.dart`) resolves the requested model, validates it, and provides the corresponding `ModelConfig` and model name string to the handler.
43
+
***Model Registry:** A central map (`lib/src/registry/model_registry.dart`) links model name strings (from the `?model=` query parameter) to model-specific configurations (`ModelConfig`), primarily containing serialization functions (`fromJson`) and ID extraction logic (`getId`).
44
+
***Dependency Injection (Dart Frog Providers):** Middleware (`routes/_middleware.dart`) is used to instantiate and provide singleton instances of each `HtDataRepository<T>` (configured with the in-memory client and fixture data), the `ModelRegistryMap`, and a unique `RequestId` per request. Route-specific middleware (`routes/api/v1/data/_middleware.dart`) resolves the requested model, validates it, and provides the corresponding `ModelConfig` and model name string to the handler.
41
45
***Centralized Error Handling:** The `errorHandler` middleware intercepts exceptions (especially `HtHttpException` subtypes and `FormatException`) and maps them to standardized JSON error responses with appropriate HTTP status codes.
42
46
43
47
## API Endpoint: `/api/v1/data`
@@ -46,6 +50,28 @@ This endpoint serves as the single entry point for accessing different data mode
0 commit comments