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 with new API features and architectural details
- Add overview of User Settings API and its endpoints
- Refactor Core Functionality section with more detailed information
- Update Technical Overview with new shared packages and patterns
- Restructure API Endpoint documentation for clarity
- Improve consistency in error handling and response structure description
`ht_api` is the backend API component of the Headlines Toolkit (HT) project. It serves as the central data provider for HT applications (like the mobile app and web dashboard), offering access to various data models required by the toolkit. Built with Dart using the Dart Frog framework, it prioritizes simplicity, maintainability, and scalability through a generic API design.
9
+
`ht_api` is the central backend API service for the Headlines Toolkit (HT) project. Built with Dart using the Dart Frog framework, it provides essential APIs to support HT client applications (like the mobile app and web dashboard). It aims for simplicity, maintainability, and scalability, currently offering APIs for data access and user settings management.
11
10
12
11
## Features
13
12
14
-
***Generic Data Endpoint (`/api/v1/data`):** Provides a unified RESTful interface for performing CRUD (Create, Read, Update, Delete) operations on multiple data models.
13
+
### Core Functionality
14
+
15
+
***Standardized Success Responses:** Returns consistent JSON success responses wrapped in a `SuccessApiResponse` structure, including request metadata (`requestId`, `timestamp`).
16
+
***Standardized Error Handling:** Returns consistent JSON error responses via centralized middleware (`lib/src/middlewares/error_handler.dart`) for predictable client-side handling.
17
+
***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.
18
+
***In-Memory Demo Mode:** Utilizes pre-loaded fixture data (`lib/src/fixtures/`) for demonstration and development purposes, simulating a live backend without external dependencies for core data and settings.
19
+
20
+
### Data API (`/api/v1/data`)
21
+
22
+
***Generic Data Endpoint:** Provides a unified RESTful interface for performing CRUD (Create, Read, Update, Delete) operations on multiple data models.
15
23
***Model Agnostic Design:** Supports various data types through a single endpoint structure, determined by the `?model=` query parameter.
16
-
***Currently Supported Models:**
24
+
***Currently Supported Data Models:**
17
25
*`headline`
18
26
*`category`
19
27
*`source`
20
28
*`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.
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.
25
-
***Standardized Error Handling:** Returns consistent JSON error responses via centralized middleware (`lib/src/middlewares/error_handler.dart`) for predictable client-side handling.
29
+
30
+
### User Settings API (`/api/v1/users/me/settings`)
31
+
32
+
***User-Specific Settings Management:** Provides RESTful endpoints for managing application settings (currently treated globally, future enhancement for user-specific).
33
+
***Supported Settings:**
34
+
* Display Settings (Theme, Font, etc.)
35
+
* Language Preference
26
36
27
37
## Technical Overview
28
38
29
39
***Language:** Dart (`>=3.0.0 <4.0.0`)
30
40
***Framework:** Dart Frog (`^1.1.0`)
31
-
***Architecture:** Layered architecture leveraging shared packages and a generic API pattern.
*`ht_shared`: Contains shared data models (`Headline`, `Category`, `Source`, `Country`, `SuccessApiResponse`, `ResponseMetadata`, etc.) used across the HT ecosystem.
36
-
*`ht_data_client`: Defines the generic `HtDataClient<T>` interface for data access operations.
37
-
*`ht_data_inmemory`: Provides the `HtDataInMemoryClient<T>` implementation, used here for the demo mode, seeded with fixture data.
38
-
*`ht_data_repository`: Defines the generic `HtDataRepository<T>` which abstracts the data client, providing a clean interface to the API route handlers.
39
-
*`ht_http_client`: Provides custom HTTP exceptions (`HtHttpException` subtypes) used for consistent error signaling, even by the in-memory client.
45
+
*`ht_shared`: Contains shared data models (`Headline`, `Category`, etc.), API response wrappers (`SuccessApiResponse`, `ResponseMetadata`), and standard exceptions (`HtHttpException`).
46
+
*`ht_data_client`: Defines the generic `HtDataClient<T>` interface.
47
+
*`ht_data_inmemory`: Provides the `HtDataInMemoryClient<T>` implementation for data.
48
+
*`ht_data_repository`: Defines the generic `HtDataRepository<T>` for data access.
49
+
*`ht_app_settings_client`: Defines the `HtAppSettingsClient` interface for settings.
50
+
*`ht_app_settings_inmemory`: Provides the `HtAppSettingsInMemory` implementation for settings.
51
+
*`ht_app_settings_repository`: Defines the `HtAppSettingsRepository` for settings management.
52
+
*`ht_http_client`: Provides custom HTTP exceptions (`HtHttpException` subtypes) used for consistent error signaling.
40
53
***Key Patterns:**
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.
42
-
***Generic Data Endpoint:** A single set of route handlers (`/api/v1/data/index.dart`, `/api/v1/data/[id].dart`) serves multiple data models.
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.
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.
54
+
***Repository Pattern:**`HtDataRepository<T>`and `HtAppSettingsRepository` provide clean abstractions over data/settings logic. Route handlers interact with repositories.
55
+
***Generic Data Endpoint:** A single set of route handlers serves multiple data models via `/api/v1/data`.
56
+
***Model Registry:** A central map (`lib/src/registry/model_registry.dart`) links data model names to configurations (`ModelConfig`) for the generic data endpoint.
57
+
***Dependency Injection (Dart Frog Providers):** Middleware (`routes/_middleware.dart`) provides singleton instances of repositories (`HtDataRepository<T>`, `HtAppSettingsRepository`), the `ModelRegistryMap`, and a unique `RequestId`.
58
+
***Centralized Error Handling:** The `errorHandler` middleware intercepts exceptions and maps them to standardized JSON error responses.
46
59
47
-
## API Endpoint: `/api/v1/data`
60
+
## API Endpoints: Data (`/api/v1/data`)
48
61
49
62
This endpoint serves as the single entry point for accessing different data models. The specific model is determined by the `model` query parameter.
## API Endpoints: User Settings (`/api/v1/users/me/settings`)
127
+
128
+
These endpoints manage application settings. Currently, they operate on a global set of settings due to the lack of authentication; future enhancements will make them user-specific.
129
+
130
+
**Standard Response Structure:** Uses the same `SuccessApiResponse` and error structure as the Data API.
131
+
132
+
**Settings Operations:**
133
+
134
+
1. **Get Display Settings**
135
+
* **Method:** `GET`
136
+
* **Path:** `/api/v1/users/me/settings/display`
137
+
* **Success Response:** `200 OK` with `SuccessApiResponse<DisplaySettings>`.
0 commit comments