-
-
Notifications
You must be signed in to change notification settings - Fork 2
docs: cookbook + learning path improvements (maintenance run 2026-02-24) #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "last_processed_ref": "v0.1.335", | ||
| "date": "2026-02-23", | ||
| "notes": "Fixed MockServer examples in testing recipe. Added Graceful Shutdown recipe. Enhanced Learning Path with 'The Email Worker' mini-project." | ||
| "date": "2026-02-24", | ||
| "notes": "Added Error Handling recipe, updated File Uploads with streaming warning, enhanced DB Integration with pagination, and improved Learning Path with Advanced Testing module." | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Docs Maintenance Run: 2026-02-24 | ||
|
|
||
| ## 1. Version Detection | ||
| - **Target Version**: v0.1.335 | ||
| - **Status**: No version change since last run (2026-02-23). | ||
| - **Mode**: Continuous Improvement. | ||
|
|
||
| ## 2. Changes | ||
| ### Learning Path | ||
| - Added **Module 11.5: Advanced Testing** to `docs/cookbook/src/learning/curriculum.md` covering `MockServer` and property testing concepts. | ||
| - Refined **Module 6.5: File Uploads** in `docs/cookbook/src/learning/curriculum.md` to explicitly warn about the buffering behavior of the `Multipart` extractor. | ||
|
|
||
| ### Recipes | ||
| - **File Uploads**: Updated `docs/cookbook/src/recipes/file_uploads.md` with a prominent warning about memory usage for large files and suggested `multer` or raw body streaming as alternatives. | ||
| - **Database Integration**: Enhanced `docs/cookbook/src/recipes/db_integration.md` with a new section on **Pagination**, demonstrating `LIMIT/OFFSET` queries and integration with `rustapi_core::hateoas::PageInfo`. | ||
| - **Error Handling**: Created a new recipe `docs/cookbook/src/recipes/error_handling.md` detailing: | ||
| - Custom `ApiError` enum implementation. | ||
| - `IntoResponse` for structured JSON errors. | ||
| - Best practices for masking internal server errors in production. | ||
|
|
||
| ## 3. Improvements | ||
| - Addressed a gap in documentation regarding advanced error handling patterns. | ||
| - Clarified performance implications of file uploads to prevent user issues with large files. | ||
| - Connected database concepts with pagination features for a more cohesive learning experience. | ||
|
|
||
| ## 4. TODOs | ||
| - [ ] Investigate if `rustapi-core` can support streaming multipart parsing natively in a future release. | ||
| - [ ] Add a full end-to-end example of the "High-Scale Event Platform" capstone project. | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -155,7 +155,60 @@ async fn transfer_credits( | |||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ## 4. Integration Testing with TestContainers | ||||||
| ## 4. Pagination with SQLx | ||||||
|
|
||||||
| When listing resources, always use `LIMIT` and `OFFSET` to avoid fetching thousands of rows. RustAPI provides helpers for standard HATEOAS pagination. | ||||||
|
|
||||||
| See the [Pagination Recipe](pagination.md) for more details on `ResourceCollection`. | ||||||
|
|
||||||
| ```rust | ||||||
| use rustapi_rs::hateoas::{PageInfo, ResourceCollection}; | ||||||
|
||||||
| use rustapi_rs::hateoas::{PageInfo, ResourceCollection}; | |
| use rustapi_rs::{PageInfo, ResourceCollection}; |
Copilot
AI
Feb 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let offset = (page * size) as i64; can overflow usize before the cast if a client sends a very large page value (wraps in release builds). Prefer doing the math in i64 with checked/saturating ops (and return a 400 if it doesn’t fit) to keep the example safe.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,140 @@ | ||||||||||||||||||||
| # Error Handling | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Effective error handling is critical for building robust APIs. RustAPI provides a standard `ApiError` type but encourages custom error handling for domain-specific logic. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ## The Standard `ApiError` | ||||||||||||||||||||
|
|
||||||||||||||||||||
| RustAPI's `ApiError` is designed to be returned directly from handlers. It implements `IntoResponse`, so it is automatically converted to a JSON response. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ```rust | ||||||||||||||||||||
| use rustapi_rs::prelude::*; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #[rustapi_rs::get("/users/{id}")] | ||||||||||||||||||||
| async fn get_user(Path(id): Path<i32>) -> Result<Json<User>, ApiError> { | ||||||||||||||||||||
| if id < 0 { | ||||||||||||||||||||
| // Returns 400 Bad Request | ||||||||||||||||||||
| return Err(ApiError::bad_request("ID cannot be negative")); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if id == 99 { | ||||||||||||||||||||
| // Returns 404 Not Found | ||||||||||||||||||||
| return Err(ApiError::not_found("User not found")); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Returns 500 Internal Server Error (and logs the details) | ||||||||||||||||||||
| // The client sees "Internal Server Error" without the sensitive details | ||||||||||||||||||||
|
Comment on lines
+24
to
+25
|
||||||||||||||||||||
| // Returns 500 Internal Server Error (and logs the details) | |
| // The client sees "Internal Server Error" without the sensitive details | |
| // Returns 500 Internal Server Error. | |
| // When converted to JSON via `ErrorResponse::from_api_error`: | |
| // - in production, the client sees a generic "An internal error occurred" | |
| // - in non-production, the provided message ("Database connection failed") is returned |
Copilot
AI
Feb 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documented default ApiError JSON shape here doesn’t match the implementation in rustapi-core: responses include error: { type, message, fields? } plus top-level error_id and optional request_id (there is no code field in the JSON body). Please update this example to reflect the actual response format so users can rely on it.
| "code": 404, | |
| "message": "User not found", | |
| "id": "req_123abc" // Request ID for tracking (if tracing is enabled) | |
| } | |
| "type": "not_found", | |
| "message": "User not found" | |
| }, | |
| "error_id": "err_123abc", | |
| "request_id": "req_456def" // Optional request ID for tracking (if tracing is enabled) |
Copilot
AI
Feb 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RustApi::handle_error does not appear to exist in this codebase (no symbol found). Please remove this API mention or replace it with the supported mechanism for customizing 404/500 handling in RustAPI.
| For errors that occur outside of handlers (e.g., in extractors or middleware), RustAPI has default handlers. You can customize 404 and 500 pages using `RustApi::handle_error` (if supported by your version) or by ensuring your extractors return your custom error type. | |
| For errors that occur outside of handlers (e.g., in extractors or middleware), RustAPI has default handlers. You can customize the behavior for 404 and 500 responses by ensuring your extractors and middleware return your custom error type (such as `ApiError` or `AppError`), so they go through the same error mapping logic as your handlers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run report says Module 11.5 covers “MockServer and property testing concepts”, but the actual curriculum changes only introduce MockServer/integration testing (no property testing content is added). Please align the run report with the curriculum (or add the missing property testing material).