Skip to content

feat(235): Split BodyCodec into BodyEncoder and BodyDecoder#236

Merged
rcardin merged 22 commits into
v0.18.0from
235-split-bodycodec-into-bodyencoder-bodydecoder
Apr 28, 2026
Merged

feat(235): Split BodyCodec into BodyEncoder and BodyDecoder#236
rcardin merged 22 commits into
v0.18.0from
235-split-bodycodec-into-bodyencoder-bodydecoder

Conversation

@rcardin
Copy link
Copy Markdown
Owner

@rcardin rcardin commented Apr 28, 2026

Closes #235

rcardin and others added 11 commits April 28, 2026 08:05
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Introduce BodyDecoder[A] as the decode-only counterpart to BodyEncoder[A],
completing the BodyCodec split. Provides given instances for String, Int,
Long, Double, and Boolean with List[DecodingError] error accumulation semantics.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…yDecoder instead of BodyCodec

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ecoder

Replace BodyCodec with BodyEncoder in HttpRequest (post/put/patch) and
with BodyDecoder in HttpResponse (as[A]), completing the client-side
split of the unified codec type.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Deleted CirceCodec.scala and replaced it with CirceInstances.scala,
providing separate circeBodyEncoder and circeBodyDecoder given instances
that preserve decodeAccumulating / List[DecodingError] semantics from #230.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…oderSpec

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace all BodyCodec mentions across READMEs and website docs to reflect
the split into BodyEncoder (encode + contentType, used by response helpers
and HttpRequest.post/put/patch) and BodyDecoder (decode, used by req.as
and HttpResponse.as). Update Circe docs to show two separate given instances,
each gated on a single Circe constraint.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rcardin rcardin self-assigned this Apr 28, 2026
@rcardin rcardin added breaking Breaking change yaes-http-server YAES Http Server module refactoring Refactoring yaes-http-client YAES Http Client module yaes-http-circe YAES integration with Circe labels Apr 28, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements the breaking refactor requested in #235 by replacing the single BodyCodec[A] typeclass with two independent typeclasses—BodyEncoder[A] and BodyDecoder[A]—and updates the server/client APIs, Circe integration, tests, and documentation accordingly.

Changes:

  • Introduce BodyEncoder[A] (with contentType + encode) and BodyDecoder[A] (with decode raising List[DecodingError]), and remove BodyCodec.
  • Update server/client APIs to depend on BodyEncoder for request/response writing and BodyDecoder for request/response reading.
  • Split and update tests + docs (including Circe integration renamed to CirceInstances and new split givens).

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
yaes-http/core/src/main/scala/in/rcard/yaes/http/core/BodyEncoder.scala Adds the new BodyEncoder typeclass and built-in primitive instances.
yaes-http/core/src/main/scala/in/rcard/yaes/http/core/BodyDecoder.scala Adds the new BodyDecoder typeclass and built-in primitive instances.
yaes-http/core/src/main/scala/in/rcard/yaes/http/core/BodyCodec.scala Removes the old combined typeclass.
yaes-http/server/src/main/scala/in/rcard/yaes/http/server/Response.scala Switches response builders to require BodyEncoder.
yaes-http/server/src/main/scala/in/rcard/yaes/http/server/Request.scala Switches Request.as[A] to require BodyDecoder.
yaes-http/server/src/test/scala/in/rcard/yaes/http/server/BodyEncoderSpec.scala New tests covering built-in + custom BodyEncoder behavior.
yaes-http/server/src/test/scala/in/rcard/yaes/http/server/BodyDecoderSpec.scala New tests covering built-in + custom BodyDecoder behavior and raised errors.
yaes-http/server/src/test/scala/in/rcard/yaes/http/server/BodyCodecSpec.scala Removes obsolete combined codec tests.
yaes-http/server/README.md Updates documentation to describe encoder/decoder split.
yaes-http/client/src/main/scala/in/rcard/yaes/http/client/HttpRequest.scala Updates post/put/patch to require BodyEncoder.
yaes-http/client/src/main/scala/in/rcard/yaes/http/client/HttpResponse.scala Updates as[A] to require BodyDecoder.
yaes-http/client/src/test/scala/in/rcard/yaes/http/client/HttpRequestSpec.scala Removes old BodyCodec import; continues exercising body-building behavior.
yaes-http/client/src/test/scala/in/rcard/yaes/http/client/HttpResponseSpec.scala Updates response decoding test naming/constraints to BodyDecoder.
yaes-http/client/src/test/scala/in/rcard/yaes/http/client/YaesClientIntegrationSpec.scala Updates integration helper to require only BodyDecoder at decode sites.
yaes-http/client/README.md Updates client docs to encoder/decoder split wording and examples.
yaes-http/circe/src/main/scala/in/rcard/yaes/http/circe/CirceInstances.scala Replaces combined Circe codec with separate circeBodyEncoder/circeBodyDecoder givens.
yaes-http/circe/src/main/scala/in/rcard/yaes/http/circe/CirceCodec.scala Removes obsolete combined Circe codec instance.
yaes-http/circe/src/test/scala/in/rcard/yaes/http/circe/CirceCodecSpec.scala Updates tests to validate independent Circe encoder/decoder resolution and behavior.
yaes-http/circe/README.md Updates Circe module docs to describe separate givens and usage.
website/src/content/docs/http/server.md Updates website server docs to encoder/decoder split and revised examples.
website/src/content/docs/http/client.md Updates website client docs to encoder/decoder split.
website/src/content/docs/http/circe.md Updates website Circe docs to separate encoder/decoder instances and usage.
Comments suppressed due to low confidence (1)

yaes-http/server/src/main/scala/in/rcard/yaes/http/server/Response.scala:56

  • The context parameter is still named codec, but the required typeclass is now BodyEncoder[A]. Renaming this parameter to encoder (and updating usages) would make the API and implementation clearer; consider applying the same rename to the other Response factory methods in this object as well.
  def ok[A](value: A)(using codec: BodyEncoder[A]): Response =
    Response(
      status = 200,
      headers = Map("Content-Type" -> codec.contentType),
      body = codec.encode(value)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread yaes-http/server/src/main/scala/in/rcard/yaes/http/server/Request.scala Outdated
Comment thread yaes-http/server/src/main/scala/in/rcard/yaes/http/server/Request.scala Outdated
Comment thread yaes-http/client/src/main/scala/in/rcard/yaes/http/client/HttpResponse.scala Outdated
Comment thread yaes-http/client/src/main/scala/in/rcard/yaes/http/client/HttpRequest.scala Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread yaes-http/circe/README.md Outdated
rcardin and others added 3 commits April 28, 2026 09:30
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <copilot@github.com>
@rcardin rcardin requested a review from Copilot April 28, 2026 07:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

yaes-http/server/src/test/scala/in/rcard/yaes/http/server/ResponseSpec.scala:23

  • Response.ok now sets the Content-Type header using Headers.ContentType (lowercase content-type), but this spec still asserts on the mixed-case key "Content-Type". This will fail because Map lookup is case-sensitive; update the assertions to use Headers.ContentType (or "content-type") consistently (same applies to the other assertions in this file).
  it should "set Content-Type from encoder for Int" in {
    val response = Response.ok(42)

    response.status shouldBe 200
    response.body shouldBe "42"
    response.headers should contain("Content-Type" -> "text/plain; charset=UTF-8")

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <copilot@github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread yaes-http/server/src/test/scala/in/rcard/yaes/http/server/ResponseSpec.scala Outdated
Comment thread yaes-http/client/src/test/scala/in/rcard/yaes/http/client/HttpResponseSpec.scala Outdated
rcardin and others added 2 commits April 28, 2026 09:53
…onseSpec.scala

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread yaes-http/core/src/main/scala/in/rcard/yaes/http/core/BodyDecoder.scala Outdated
Comment thread yaes-http/core/src/main/scala/in/rcard/yaes/http/core/BodyEncoder.scala Outdated
rcardin and others added 2 commits April 28, 2026 10:06
Co-authored-by: Copilot <copilot@github.com>
@rcardin rcardin requested a review from Copilot April 28, 2026 08:06
@rcardin rcardin merged commit b03551e into v0.18.0 Apr 28, 2026
1 check passed
@rcardin rcardin deleted the 235-split-bodycodec-into-bodyencoder-bodydecoder branch April 28, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaking change refactoring Refactoring yaes-http-circe YAES integration with Circe yaes-http-client YAES Http Client module yaes-http-server YAES Http Server module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants