Skip to content

Commit

Permalink
Add json entity
Browse files Browse the repository at this point in the history
  • Loading branch information
noelwelsh committed Jan 21, 2024
1 parent 3c35cc9 commit cedb4ad
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/shared/src/main/scala/krop/route/Entity.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package krop.route

import cats.effect.IO
import io.circe.Json
import org.http4s.DecodeResult
import org.http4s.EntityDecoder
import org.http4s.EntityEncoder
Expand All @@ -25,6 +26,7 @@ import org.http4s.MediaRange
import org.http4s.headers.`Content-Type`
import org.http4s.syntax.all.*
import scalatags.Text.TypedTag
import org.http4s.circe.{CirceEntityDecoder, CirceEntityEncoder}

/** Type alias for an Entity where the decoded and encoded type are the same. */
type InvariantEntity[A] = Entity[A, A]
Expand Down Expand Up @@ -69,6 +71,12 @@ final case class Entity[D, E](
)
}
object Entity {
val json: InvariantEntity[Json] =
Entity(
CirceEntityDecoder.circeEntityDecoder,
CirceEntityEncoder.circeEntityEncoder
)

val unit: InvariantEntity[Unit] =
Entity(
EntityDecoder.decodeBy[IO, Unit](MediaRange.`*/*`)(_ =>
Expand Down

0 comments on commit cedb4ad

Please sign in to comment.