Skip to content

feat(envelopes): support multiple response types with shared extension methods#213

Merged
j-d-ha merged 39 commits into
mainfrom
feature/#212-support-multiple-response-types-with-same-envelope-base
Dec 15, 2025
Merged

feat(envelopes): support multiple response types with shared extension methods#213
j-d-ha merged 39 commits into
mainfrom
feature/#212-support-multiple-response-types-with-same-envelope-base

Conversation

@j-d-ha

@j-d-ha j-d-ha commented Dec 2, 2025

Copy link
Copy Markdown
Collaborator

🚀 Pull Request

📋 Summary

This PR introduces a unified HTTP result abstraction (IHttpResult<TSelf>) that enables shared extension methods across ALB, API Gateway v1, and API Gateway v2 response types. By leveraging C# 14's extension blocks, developers can now use the same fluent API (.Ok(), .Created(), .NotFound(), etc.) across all three Lambda HTTP integration types.

Key Changes:

  • Added IHttpResult<TSelf> interface as a common contract for HTTP responses
  • Implemented BaseHttpResultExtensions with core factory methods (StatusCode, Text, Json, Customize)
  • Implemented HttpResultExtensions with convenience methods for common HTTP status codes (200, 201, 400, 404, 500, etc.)
  • Updated AlbResult, ApiGatewayResult, and ApiGatewayV2Result to implement IHttpResult<TSelf>
  • Added comprehensive unit tests for all extension methods across all three result types
  • Updated documentation to reflect the new shared API

Benefits:

  • Eliminates code duplication across envelope types
  • Provides a consistent developer experience regardless of Lambda integration type
  • Leverages C# 14's extension blocks for elegant, type-safe fluent APIs
  • Makes it easy to switch between ALB/API Gateway v1/v2 without changing handler code

✅ Checklist

  • My changes build cleanly
  • I've added/updated relevant tests
  • I've added/updated documentation or README
  • I've followed the coding style for this project
  • I've tested the changes locally (if applicable)

🧪 Related Issues or PRs

Closes #212


💬 Notes for Reviewers

The use of C# 14 extension blocks (extension<THttpResult>(IHttpResult<THttpResult>)) is intentional and correct syntax. This enables the extension methods to be callable on the interface while returning the concrete type for fluent chaining.

All three HTTP result types (AlbResult, ApiGatewayResult, ApiGatewayV2Result) now share the same extension methods, eliminating the need for duplicate implementations.

@j-d-ha j-d-ha changed the title feat(api-gateway): add support for multiple response types with same envelope base feat(envelopes): add support for multiple response types with same envelope base Dec 2, 2025
@j-d-ha
j-d-ha requested a review from ncipollina December 2, 2025 12:40
- Updated handler to utilize `ApiGatewayResponseEnvelopes` for dual response types.
- Added support for bad request responses with `ErrorDetails`.
- Introduced utility methods (`Ok`, `BadRequest`) for response creation.
- Extended JSON serialization to include `ErrorDetails`.
…ewayResult`

- Updated all references from `ApiGatewayResponseEnvelope` to `ApiGatewayResult`.
- Renamed test classes and methods to align with the new type name.
- Adjusted extension methods in `Program.cs` to work with `ApiGatewayResult`.
- Simplified response creation to use new naming conventions.
- Enhanced JSON serialization logic to accommodate updated class structure.
- Updated `LocalDevTasks.yml` to include a `--config-storage-path` option for the lambda test tool.
- Added a default API Gateway request example in `lambda_test_tool/SavedRequests`.
- Added `Microsoft.AspNetCore.Http` reference to project file for API Gateway use cases.
- Updated `Directory.Packages.props` with version `2.3.0` for consistent dependency management.
…velope` to `ApiGatewayResult`

- Renamed `ApiGatewayResponseEnvelope` to `ApiGatewayResult` across the project for consistency.
- Updated test class and method names to align with the new naming convention.
- Adjusted logic in tests and production code to work with the renamed classes.
- Introduced a new `ApiGatewayResult` file for improved structure and clarity.
- Removed `ApiGatewayResponseEnvelope` related artifacts and references.
…sions

- Streamlined handler implementation in `Program.cs` for better clarity.
- Removed redundant `#region` and unused import statements.
- Eliminated `ApiGatewayResultExtensions` to reduce duplication.
- Enhanced response handling with header support in `ApiGatewayResult.Ok`.
- Adjusted JSON serialization types to match updated logic.
…ode factories

- Added factory methods for various status codes, including `NoContent`, `Unauthorized`, `NotFound`,
  `Conflict`, and `UnprocessableEntity`.
- Updated existing methods to improve consistency by renaming `Status` to `StatusCode`.
- Enhanced readability with categorized comments for status code methods.
…piGatewayResult`

- Introduced `Created()` and `Created<T>(T bodyContent)` factory methods to handle `201 Created`.
- Updated comments for better categorization and consistency with status code methods.
@j-d-ha
j-d-ha force-pushed the feature/#212-support-multiple-response-types-with-same-envelope-base branch from b3b0844 to 958bbf9 Compare December 14, 2025 22:38
…y.Packages.props

- Added `Microsoft.AspNetCore.Http` version `2.3.0` to support enhanced HTTP scenarios.
- Ensured consistent dependency tracking in `Directory.Packages.props`.
…`ApiGatewayResult`

- Changed namespace from `AwsLambda.Host.Envelopes.ApiGateway` to `MinimalLambda.Envelopes.ApiGateway`.
- Replaced `AwsLambda.Host.Options` with `MinimalLambda.Options` for consistency.
…e handling

- Updated `ApiGatewayResult` to implement `IHttpResult<ApiGatewayResult>` for generalized usage.
- Replaced multiple factory methods with a single generalized static factory method.
- Removed redundant status code-specific static methods for streamlined extensibility.
- Introduced `IHttpResult` interface to standardize HTTP response contract.
- Added support for reusable status code handling with `BaseHttpResultExtensions` and `HttpResultExtensions`.
- Simplified implementation and enhanced flexibility for custom HTTP responses in API Gateway.
…t tool command

- Updated `LocalDevTasks.yml` to include `--config-storage-path` for improved configurability.
…t methods from `ApiGatewayResult`

- Added `ApiGatewayV2Result` to support AWS HTTP API Gateway v2 response handling.
- Removed redundant methods and comments from `ApiGatewayResult` for cleaner implementation.
- Updated `IHttpResult` interface with extended HTTP response properties.
- Introduced extensions for header handling with `UpdateHttpResultExtensions`.
- Simplified and streamlined codebase for improved maintainability and flexibility.
- Created `MinimalLambda.Envelopes` project targeting `net8.0`, `net9.0`, and `net10.0`.
- Enabled nullable reference types, implicit usings, and preview language features.
- Configured project for NuGet package generation with metadata placeholders.
- Added `README.md` for documentation and included it in the package.
- Integrated the new project into `MinimalLambda.sln`.
…handling

- Moved `BaseHttpResultExtensions`, `HttpResultExtensions`, and `UpdateHttpResultExtensions`
  into separate files for modularity.
- Revamped `ApiGatewayV2Result` to improve response handling with added flexibility.
- Updated `MinimalLambda.Envelopes.ApiGateway` and project references to align with changes.
- Added `Microsoft.AspNetCore.Http.Abstractions` package for HTTP helper methods and integrations.
- Removed duplicate or redundant logic from `IHttpResult`.
…ctory.Packages.props`

- Removed unused `Microsoft.AspNetCore.Http` package (version `2.3.0`) for dependency cleanup.
- Ensured all references to this package were unnecessary before removal.
…omization

- Added new `AlbResult` class for Application Load Balancer response handling.
- Implemented `Configure` method in `ApiGatewayResult` and `ApiGatewayV2Result` for customizations.
- Updated `IHttpResult` interface with a new `Configure` method.
- Added `MinimalLambda.Envelopes` project reference to `MinimalLambda.Envelopes.Alb`.
- Improved examples with `Configure` usage for custom headers and multi-value headers.
…result classes

- Updated `Configure` to `Customize` in `ApiGatewayResult`, `ApiGatewayV2Result`, and `AlbResult`.
- Adjusted `IHttpResult` interface to use `Customize` method instead of `Configure`.
- Modified examples to reflect the method name change for better clarity and intent.
- Deleted `UpdateHttpResultExtensions.cs` as it is no longer used or required.
- Simplified the codebase by removing unnecessary extension methods for headers and content types.
- Added XML documentation to `HttpResultExtensions` for method clarity and usability.
- Provided summaries, parameter descriptions, and return value details for all HTTP status code methods.
- Updated `BaseHttpResultExtensions` with XML comments for factory methods.
- Enhanced `IHttpResult` interface with comprehensive XML documentation for properties and methods.
…reate` methods

- Added `inheritdoc` XML documentation for `Customize` method in `ApiGatewayResult`, `ApiGatewayV2Result`, and `AlbResult`.
- Applied `inheritdoc` XML documentation for `Create` method in all affected result classes.
- Improved code clarity with consistent use of XML comments.
- Added detailed XML summaries and remarks to `ApiGatewayResult`, `ApiGatewayV2Result`, and `AlbResult`.
- Improved clarity by explaining usage scenarios for each result class.
- Enhanced API documentation for better usability and maintainability.
- Removed `Customize` method from `ApiGatewayResult`, `ApiGatewayV2Result`, and `AlbResult`.
- Simplified `IHttpResult` interface by excluding `Customize` method.
- Refactored `BaseHttpResultExtensions` to provide `Customize` functionality as an extension method.
- Updated namespaces in all affected files for consistency with the project structure.
….Events`

- Included `MinimalLambda.Envelopes` namespace in the example project for envelope handling.
- Enhanced `examples/MinimalLambda.Example.Events/Program.cs` with additional import for functionality consistency.
…meters

- Removed the `body` parameter from all `Create` method overloads in result classes.
- Updated `IHttpResult` interface and implementations to reflect the changes.
- Refactored `BaseHttpResultExtensions` to align with streamlined method signatures.
- Improved overall code readability and reduced unnecessary complexity.
…used extension methods

- Deleted `IHttpResult2<TSelf>` as it was not referenced or utilized in the project.
- Removed unused `MyExtension` class and its `Create` extension method.
- Simplified `IHttpResult` by excluding unnecessary extensions and duplicate abstractions.
- Updated project file with a meaningful package description.
- Added a comprehensive `README.md` for `MinimalLambda.Envelopes` package.
- Included usage information, documentation links, and related package details.
…E files

- Updated multiple README files to include references to the `MinimalLambda.Envelopes` package.
- Added links to the NuGet package and download badges for consistency and accessibility.
- Improved documentation to ensure comprehensive package visibility across projects.
…ult` documentation to README

- Updated `MinimalLambda.Envelopes.Alb` README with details on `AlbResult` class and its fluent API.
- Updated `MinimalLambda.Envelopes.ApiGateway` README with details on `ApiGatewayResult` and `ApiGatewayV2Result` classes.
- Highlighted usage scenarios, response methods, and customization options.
- Added code samples and guidance for registering serializers with multiple result types.
…package features

- Included a comprehensive explanation of the `MinimalLambda.Envelopes` infrastructure package.
- Added documentation for the Response Builder API with usage examples and supported result classes.
- Detailed AOT serializer configuration with examples for registering envelope and result types.
- Highlighted scenarios for using result classes vs. envelopes directly.
…s` references

- Added `MinimalLambda.Envelopes` to the installation guide table with usage scenarios.
- Updated example code to use the streamlined `ApiGatewayResult.Ok` response builder.
- Included NuGet package badge and download count for `MinimalLambda.Envelopes` in the index.
- Updated `Directory.Build.props` to reflect the new version 2.0.0-beta.7.
- Added tests for `StatusCode`, `Text`, and `Json` methods to verify result creation behavior.
- Verified default headers, content types, and response body generation in tests.
- Implemented a test for `Customize` extension to ensure property modification and chaining.
- Utilized `AutoFixture` for generating test payloads and validated serialized responses.

chore(project): update test project settings and language version

- Updated `MinimalLambda.Envelopes.UnitTests.csproj` to use `LangVersion=preview`.
- Implemented tests for various result types: `Ok`, `Created`, `NoContent`, `BadRequest`, and more.
- Verified response behavior, including status codes, headers, and JSON body content.
- Utilized `AutoFixture` for generating test payloads to ensure test repeatability.
- Ensured compatibility with the `AlbResult` response builder and `EnvelopeOptions`.
- Implemented tests for `Accepted`, `MovedPermanently`, `Found`, and `Forbidden` result types.
- Verified response behavior, including status codes, headers, and JSON body content.
- Added support for testing results with and without body content, including `Location` header checks.
- Utilized `AutoFixture` for generating test payloads and validated JSON serialization behavior.
@j-d-ha j-d-ha changed the title feat(envelopes): add support for multiple response types with same envelope base feat(envelopes): support multiple response types with shared extension methods Dec 15, 2025
@j-d-ha
j-d-ha marked this pull request as ready for review December 15, 2025 12:33
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@codecov

codecov Bot commented Dec 15, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.97315% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...Envelopes/MinimalLambda.Envelopes.Alb/AlbResult.cs 91.66% 1 Missing and 1 partial ⚠️
...malLambda.Envelopes.ApiGateway/ApiGatewayResult.cs 91.30% 1 Missing and 1 partial ⚠️
...lLambda.Envelopes.ApiGateway/ApiGatewayV2Result.cs 91.30% 1 Missing and 1 partial ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #213      +/-   ##
==========================================
+ Coverage   88.09%   88.31%   +0.22%     
==========================================
  Files         122      127       +5     
  Lines        2864     3013     +149     
  Branches      334      337       +3     
==========================================
+ Hits         2523     2661     +138     
- Misses        211      219       +8     
- Partials      130      133       +3     
Files with missing lines Coverage Δ
...inimalLambda.Envelopes/BaseHttpResultExtensions.cs 100.00% <100.00%> (ø)
...es/MinimalLambda.Envelopes/HttpResultExtensions.cs 100.00% <100.00%> (ø)
...Envelopes/MinimalLambda.Envelopes.Alb/AlbResult.cs 91.66% <91.66%> (ø)
...malLambda.Envelopes.ApiGateway/ApiGatewayResult.cs 91.30% <91.30%> (ø)
...lLambda.Envelopes.ApiGateway/ApiGatewayV2Result.cs 91.30% <91.30%> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f80e306...7cafce3. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Added `Create` methods to `ApiGatewayResult`, `ApiGatewayV2Result`, and `AlbResult` classes.
- Simplified wrapping response envelopes into result objects with type parameter support.
- Improved API documentation with XML comments for new methods.

feat(tests): add unit tests for `Create` methods in result classes

- Implemented unit tests for `ApiGatewayResult.Create`, `ApiGatewayV2Result.Create`, and `AlbResult.Create`.
- Verified correct status codes, headers, and payload handling with different envelopes.
- Ensured `IsBase64Encoded` property and header presence are properly validated in tests.
@github-actions github-actions Bot added the type: feat New feature label Dec 15, 2025
j-d-ha and others added 2 commits December 15, 2025 09:29
- Simplified method summary to clarify strongly typed body usage.
- Removed redundant remarks for clearer documentation format.
@sonarqubecloud

Copy link
Copy Markdown

@j-d-ha
j-d-ha merged commit 4afcbbb into main Dec 15, 2025
11 checks passed
@j-d-ha
j-d-ha deleted the feature/#212-support-multiple-response-types-with-same-envelope-base branch December 15, 2025 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feat New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(host): support multiple response types with same envelope base

1 participant