Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
cornerman committed Jun 10, 2024
1 parent dfa4f30 commit 2034165
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down

0 comments on commit 2034165

Please sign in to comment.