Skip to content

Commit 6d7f68a

Browse files
committed
docs: update API docs for auth and user settings
- Clarify auth required for data API - Update user settings API path - Add auth required to user settings API
1 parent 6cd2b77 commit 6d7f68a

File tree

1 file changed

+39
-24
lines changed

1 file changed

+39
-24
lines changed

README.md

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,24 @@
1616
* **Standardized Error Handling:** Returns consistent JSON error responses via centralized middleware (`lib/src/middlewares/error_handler.dart`) for predictable client-side handling.
1717
* **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.
1818
* **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, settings, and email sending.
19-
* **Authentication:** Provides endpoints for user sign-in/sign-up via email code and anonymous sign-in. Includes token generation and validation via middleware.
19+
* **Authentication:** Provides endpoints for user sign-in/sign-up via email code and anonymous sign-in. Includes token generation and validation. All Data and User Settings API endpoints now require authentication.
2020

2121
### Data API (`/api/v1/data`)
2222

23+
* **Authentication Required:** All operations on this endpoint require a valid authentication token.
2324
* **Generic Data Endpoint:** Provides a unified RESTful interface for performing CRUD (Create, Read, Update, Delete) operations on multiple data models.
2425
* **Model Agnostic Design:** Supports various data types through a single endpoint structure, determined by the `?model=` query parameter.
25-
* **Currently Supported Data Models:**
26+
* **Data Scoping:** Can serve global data (e.g., news articles, accessible to any authenticated user) or user-specific data (for future models, accessible only to the authenticated owner), based on the model's server-side configuration (`ModelConfig.ownership`).
27+
* **Currently Supported Data Models (as global):**
2628
* `headline`
2729
* `category`
2830
* `source`
2931
* `country`
3032

31-
### User Settings API (`/api/v1/users/me/settings`)
33+
### User Settings API (`/api/v1/users/{userId}/settings`)
3234

33-
* **User-Specific Settings Management:** Provides RESTful endpoints for managing application settings (currently treated globally, future enhancement for user-specific).
35+
* **User-Specific Settings Management:** Provides RESTful endpoints for an authenticated user to manage their own application settings. The `{userId}` in the path must match the ID of the authenticated user.
36+
* **Authentication Required:** All operations require a valid authentication token.
3437
* **Supported Settings:**
3538
* Display Settings (Theme, Font, etc.)
3639
* Language Preference
@@ -139,9 +142,11 @@ These endpoints handle user authentication flows.
139142

140143
## API Endpoints: Data (`/api/v1/data`)
141144

145+
**Authentication required for all operations.**
146+
142147
This endpoint serves as the single entry point for accessing different data models. The specific model is determined by the `model` query parameter.
143148

144-
**Supported `model` values:** `headline`, `category`, `source`, `country`
149+
**Supported `model` values (currently global):** `headline`, `category`, `source`, `country`
145150

146151
**Standard Response Structure:** (Applies to both Data and Settings APIs)
147152

@@ -179,69 +184,79 @@ This endpoint serves as the single entry point for accessing different data mode
179184
* **Path:** `/api/v1/data?model=<model_name>`
180185
* **Request Body:** JSON object representing the item to create (using `camelCase` keys).
181186
* **Success Response:** `201 Created` with `SuccessApiResponse<T>` containing the created item.
182-
* **Example:** `POST /api/v1/data?model=category` with body `{"name": "Sports", "description": "News about sports"}`
187+
* **Example:** `POST /api/v1/data?model=category` with body `{"name": "Sports", "description": "News about sports"}` (Requires Bearer token)
183188

184189
3. **Get Item by ID**
185190
* **Method:** `GET`
186191
* **Path:** `/api/v1/data/<item_id>?model=<model_name>`
192+
* **Authentication:** Required (Bearer Token).
187193
* **Success Response:** `200 OK` with `SuccessApiResponse<T>`.
188-
* **Error Response:** `404 Not Found`.
189-
* **Example:** `GET /api/v1/data/some-headline-id?model=headline`
194+
* **Error Response:** `401 Unauthorized`, `404 Not Found`.
195+
* **Example:** `GET /api/v1/data/some-headline-id?model=headline` (Requires Bearer token)
190196

191197
4. **Update Item by ID**
192198
* **Method:** `PUT`
193199
* **Path:** `/api/v1/data/<item_id>?model=<model_name>`
200+
* **Authentication:** Required (Bearer Token).
194201
* **Request Body:** JSON object representing the complete updated item (must include `id`, using `camelCase` keys).
195202
* **Success Response:** `200 OK` with `SuccessApiResponse<T>`.
196-
* **Error Response:** `404 Not Found`, `400 Bad Request`.
197-
* **Example:** `PUT /api/v1/data/some-category-id?model=category` with updated category JSON (e.g., `{"id": "...", "name": "...", "description": "..."}`).
203+
* **Error Response:** `401 Unauthorized`, `404 Not Found`, `400 Bad Request`.
204+
* **Example:** `PUT /api/v1/data/some-category-id?model=category` with updated category JSON (Requires Bearer token).
198205

199206
5. **Delete Item by ID**
200207
* **Method:** `DELETE`
201208
* **Path:** `/api/v1/data/<item_id>?model=<model_name>`
209+
* **Authentication:** Required (Bearer Token).
202210
* **Success Response:** `204 No Content`.
203-
* **Error Response:** `404 Not Found`.
204-
* **Example:** `DELETE /api/v1/data/some-source-id?model=source`
211+
* **Error Response:** `401 Unauthorized`, `404 Not Found`.
212+
* **Example:** `DELETE /api/v1/data/some-source-id?model=source` (Requires Bearer token)
213+
214+
## API Endpoints: User Settings (`/api/v1/users/{userId}/settings`)
205215

206-
## API Endpoints: User Settings (`/api/v1/users/me/settings`)
216+
These endpoints manage application settings for an authenticated user. The `{userId}` in the path must match the ID of the authenticated user.
207217

208-
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.
218+
**Authentication Required for all operations.**
209219

210220
**Standard Response Structure:** Uses the same `SuccessApiResponse` and error structure as the Data API.
211221

212222
**Settings Operations:**
213223

214224
1. **Get Display Settings**
215225
* **Method:** `GET`
216-
* **Path:** `/api/v1/users/me/settings/display`
226+
* **Path:** `/api/v1/users/{userId}/settings/display`
217227
* **Success Response:** `200 OK` with `SuccessApiResponse<DisplaySettings>`.
218-
* **Example:** `GET /api/v1/users/me/settings/display`
228+
* **Error Response:** `401 Unauthorized`, `403 Forbidden`.
229+
* **Example:** `GET /api/v1/users/user-abc-123/settings/display` (Requires Bearer token for user-abc-123)
219230

220231
2. **Update Display Settings**
221232
* **Method:** `PUT`
222-
* **Path:** `/api/v1/users/me/settings/display`
233+
* **Path:** `/api/v1/users/{userId}/settings/display`
223234
* **Request Body:** JSON object representing the complete `DisplaySettings` (using `camelCase` keys).
224235
* **Success Response:** `200 OK` with `SuccessApiResponse<DisplaySettings>` containing the updated settings.
225-
* **Example:** `PUT /api/v1/users/me/settings/display` with body `{"baseTheme": "dark", "accentTheme": "newsRed", ...}`.
236+
* **Error Response:** `401 Unauthorized`, `403 Forbidden`, `400 Bad Request`.
237+
* **Example:** `PUT /api/v1/users/user-abc-123/settings/display` with body `{"baseTheme": "dark", ...}` (Requires Bearer token for user-abc-123).
226238

227239
3. **Get Language Setting**
228240
* **Method:** `GET`
229-
* **Path:** `/api/v1/users/me/settings/language`
241+
* **Path:** `/api/v1/users/{userId}/settings/language`
230242
* **Success Response:** `200 OK` with `SuccessApiResponse<Map<String, String>>` (e.g., `{"data": {"language": "en"}, ...}`).
231-
* **Example:** `GET /api/v1/users/me/settings/language`
243+
* **Error Response:** `401 Unauthorized`, `403 Forbidden`.
244+
* **Example:** `GET /api/v1/users/user-abc-123/settings/language` (Requires Bearer token for user-abc-123)
232245

233246
4. **Update Language Setting**
234247
* **Method:** `PUT`
235-
* **Path:** `/api/v1/users/me/settings/language`
248+
* **Path:** `/api/v1/users/{userId}/settings/language`
236249
* **Request Body:** JSON object `{"language": "<code>"}` (e.g., `{"language": "es"}`).
237250
* **Success Response:** `200 OK` with `SuccessApiResponse<Map<String, String>>` containing the updated language setting.
238-
* **Example:** `PUT /api/v1/users/me/settings/language` with body `{"language": "fr"}`.
251+
* **Error Response:** `401 Unauthorized`, `403 Forbidden`, `400 Bad Request`.
252+
* **Example:** `PUT /api/v1/users/user-abc-123/settings/language` with body `{"language": "fr"}` (Requires Bearer token for user-abc-123).
239253

240254
5. **Clear All Settings**
241255
* **Method:** `DELETE`
242-
* **Path:** `/api/v1/users/me/settings`
256+
* **Path:** `/api/v1/users/{userId}/settings`
243257
* **Success Response:** `204 No Content`.
244-
* **Example:** `DELETE /api/v1/users/me/settings`
258+
* **Error Response:** `401 Unauthorized`, `403 Forbidden`.
259+
* **Example:** `DELETE /api/v1/users/user-abc-123/settings` (Requires Bearer token for user-abc-123)
245260

246261
## Setup & Running
247262

0 commit comments

Comments
 (0)