feat(235): Split BodyCodec into BodyEncoder and BodyDecoder#236
Conversation
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>
There was a problem hiding this comment.
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](withcontentType+encode) andBodyDecoder[A](withdecoderaisingList[DecodingError]), and removeBodyCodec. - Update server/client APIs to depend on
BodyEncoderfor request/response writing andBodyDecoderfor request/response reading. - Split and update tests + docs (including Circe integration renamed to
CirceInstancesand 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 nowBodyEncoder[A]. Renaming this parameter toencoder(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.
There was a problem hiding this comment.
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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <copilot@github.com>
…tps://github.com/rcardin/yaes into 235-split-bodycodec-into-bodyencoder-bodydecoder
There was a problem hiding this comment.
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.oknow sets the Content-Type header usingHeaders.ContentType(lowercasecontent-type), but this spec still asserts on the mixed-case key "Content-Type". This will fail becauseMaplookup is case-sensitive; update the assertions to useHeaders.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>
There was a problem hiding this comment.
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.
…onseSpec.scala Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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.
Co-authored-by: Copilot <copilot@github.com>
…tps://github.com/rcardin/yaes into 235-split-bodycodec-into-bodyencoder-bodydecoder
Closes #235