From 2034165f1fbbb9bece35d2659b8a30773fa7c6aa Mon Sep 17 00:00:00 2001 From: johannes karoff Date: Tue, 11 Jun 2024 00:20:58 +0200 Subject: [PATCH] update readme --- README.md | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 232bdff..4433c81 100644 --- a/README.md +++ b/README.md @@ -20,14 +20,10 @@ This will not bloat your project. It only has an effect if you explicitly depend Get latest release: ```scala -libraryDependencies += "com.github.cornerman" %%% "chameleon" % "0.3.5" +libraryDependencies += "com.github.cornerman" %%% "chameleon" % "0.4.0" ``` -Or get development snapshots via jitpack: -```scala -resolvers += "jitpack" at "https://jitpack.io" -libraryDependencies += "com.github.cornerman.chameleon" %%% "chameleon" % "master-SNAPSHOT" -``` +We additionally publish sonatype snapshots for every commit on master. # Usage @@ -54,6 +50,39 @@ Have typeclasses for cats (`Contravariant`, `Functor`, `Invariant`): import chameleon.ext.cats._ ``` +## http4s + +We have an extra package to integrate `http4s` with chameleon `Serializer` and `Deserializer`. Specifically to create `EntityEncoder` and `EntityDecoder`. + +Usage: +```scala +libraryDependencies += "com.github.cornerman" %%% "chameleon-http4s" % "0.4.0" +``` + +To work with json inside your API: +```scala +import chameleon.ext.http4s.JsonStringCodec.* +import chameleon.ext.upickle.* + +// serialize case class as json response +Ok(json(MyCaseClass("hallo"))) + +// deserialize json request into case class +jsonAs[MyCaseClass](someRequest) +``` + +You can also use the auto import, which provides implicit `EntityEncoder` / `EntityDecoder` for all types with `Serializer` / `Deserializer`. This should only be imported when exclusively working with json. +```scala +import chameleon.ext.http4s.JsonStringCodec.auto.* +import chameleon.ext.upickle.* + +// serialize +Ok(MyCaseClass("hallo")) + +// deserialize +someRequest.as[MyCaseClass] +``` + # Motivation Say, you want to write a library that needs serialization but abstracts over the type of serialization. Then you might end up with something like this: