Skip to content
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

HttpCodec header constructor based on Schema #3232

Open
987Nabil opened this issue Dec 4, 2024 · 10 comments · May be fixed by #3270
Open

HttpCodec header constructor based on Schema #3232

987Nabil opened this issue Dec 4, 2024 · 10 comments · May be fixed by #3270
Assignees
Labels
💎 Bounty ♾️ Endpoint Endpoint API related issue enhancement New feature or request

Comments

@987Nabil
Copy link
Contributor

987Nabil commented Dec 4, 2024

Should work the same as with query params.
I was thinking that we could even do an equivalent to queryAll that takes a case class and looks up all headers that correlate with the field names.

@987Nabil 987Nabil added enhancement New feature or request ♾️ Endpoint Endpoint API related issue labels Dec 4, 2024
@jdegoes
Copy link
Member

jdegoes commented Dec 4, 2024

/bounty $750

Copy link

algora-pbc bot commented Dec 4, 2024

💎 $750 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #3232 with your implementation plan
  2. Submit work: Create a pull request including /claim #3232 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-http!

Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🔴 @987Nabil Dec 4, 2024, 3:12:32 PM #3270
🟡 @PastSmartLink Jan 2, 2025, 12:58:52 PM WIP

@987Nabil
Copy link
Contributor Author

987Nabil commented Dec 4, 2024

/attempt #3232

Algora profile Completed bounties Tech Active attempts Options
@987Nabil    99 ZIO bounties
+ 4 bounties from 2 projects
Scala
Cancel attempt

Copy link

algora-pbc bot commented Dec 11, 2024

@987Nabil: Reminder that in 7 days the bounty will become up for grabs, so please submit a pull request before then 🙏

Copy link

algora-pbc bot commented Dec 18, 2024

The bounty is up for grabs! Everyone is welcome to /attempt #3232 🙌

@987Nabil 987Nabil self-assigned this Dec 19, 2024
@987Nabil
Copy link
Contributor Author

It turns out we need here more complex changes. I'll keep working on it. Might take a while.

@PastSmartLink
Copy link

PastSmartLink commented Jan 2, 2025

Comment /attempt #3232 # Implementation Plan: HttpCodec Header Constructor Based on Schema (#3232)

Objective

Enhance HttpCodec to support constructing headers based on a provided schema, similar to how query parameters are handled. Additionally, provide functionality to map headers to a case class.


Steps to Implement

1. Analyze Existing Code

  • Review the current implementation of HttpCodec for query parameters and headers.
  • Understand how query parameters map to schemas and case classes.
  • Identify reusable components and potential changes for header support.

2. Design Schema Integration for Headers

  • Define a mechanism for associating HTTP headers with schema fields.
  • Ensure that field names in the schema map correctly to header names (consider case-insensitivity for headers).
  • Support custom header name mappings using annotations or similar mechanisms.

3. Implement Header-to-Schema Mapping

  • Extend HttpCodec to parse headers based on a schema.
    • Add a method fromHeaders(schema: Schema[T]): HttpCodec[T] to construct a codec for headers.
    • Parse headers from the request into the corresponding fields of the schema.
  • Implement error handling for missing or invalid headers.

4. Add queryAll Equivalent for Headers

  • Create a method headerAll[T](schema: Schema[T]): HttpCodec[T].
    • Collect all headers matching the field names in the schema.
    • Populate a case class instance with the values from the headers.

5. Testing

Unit Tests

  • Write unit tests for the new header-to-schema mapping functionality.
  • Test various scenarios, including:
    • Exact field-to-header name matches.
    • Custom header name mappings.
    • Missing or invalid headers.

Integration Tests

  • Validate that the new functionality integrates seamlessly with existing HttpCodec features.
  • Test with real HTTP requests and responses.

6. Documentation

  • Update the project documentation to include:
    • Usage examples for the new header constructor based on schema.
    • Guidelines on using the headerAll method.
  • Add comments in the code to explain the new methods and their functionality.

7. Code Review and Refinement

  • Submit a pull request with the implementation and include /claim #3232 in the PR body.
  • Address any feedback from the maintainers and the community.

Optional Enhancements

  • Provide support for custom header value transformations (e.g., decoding/encoding).
  • Implement caching or optimization for schema lookups if performance becomes a concern.
  • Add utilities for case-insensitive schema mappings.

Timeline

  1. Day 1-2: Analyze existing code and design the schema integration for headers.
  2. Day 3-5: Implement the core functionality and unit tests.
  3. Day 6-7: Write integration tests and documentation.
  4. Day 8: Submit the pull request and address initial feedback.

Deliverables

  1. Updated HttpCodec with header-to-schema functionality.
  2. Comprehensive unit and integration tests.
  3. Updated documentation and usage examples.

Note: Ensure code adheres to the project's contribution guidelines and coding standards.

@987Nabil
Copy link
Contributor Author

987Nabil commented Jan 3, 2025

@PastSmartLink Please read my last message. I am still working on it and we need a redesign. This is discussed with @jdegoes and you will waste your time working on this.

Copy link

algora-pbc bot commented Jan 9, 2025

@PastSmartLink: Reminder that in 7 days the bounty will become up for grabs, so please submit a pull request before then 🙏

987Nabil added a commit to 987Nabil/zio-http that referenced this issue Jan 9, 2025
987Nabil added a commit to 987Nabil/zio-http that referenced this issue Jan 9, 2025
987Nabil added a commit to 987Nabil/zio-http that referenced this issue Jan 9, 2025
Copy link

algora-pbc bot commented Jan 9, 2025

💡 @987Nabil submitted a pull request that claims the bounty. You can visit your bounty board to reward.

987Nabil added a commit to 987Nabil/zio-http that referenced this issue Jan 9, 2025
987Nabil added a commit to 987Nabil/zio-http that referenced this issue Jan 9, 2025
987Nabil added a commit to 987Nabil/zio-http that referenced this issue Jan 9, 2025
987Nabil added a commit to 987Nabil/zio-http that referenced this issue Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💎 Bounty ♾️ Endpoint Endpoint API related issue enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants