RequestBody

com.worxbend.codeberg4s.core.RequestBody
See theRequestBody companion object
sealed trait RequestBody

The payload of a request, as far as core is concerned.

Core never imports a JSON library, so a body reaches it already serialised: the codec module renders a wire DTO into a string and hands it over. The transport adapter is what turns a case of this type into bytes and sets the Content-Type header.

Every case names its own media type rather than leaving the transport to guess, because Forgejo is not uniform here: /markdown consumes JSON while /markdown/raw consumes text/plain, and a release asset is multipart/form-data with a named file part. Encoding those differences as separate cases keeps them visible in the request builder instead of hidden in a header override.

==Why this is a sealed trait and not an enum==

RequestBody.Binary and RequestBody.Multipart carry an Array[Byte], and an array's own equals in Scala is '''identity''' — two arrays holding the same bytes are not equal to each other. A case whose equality is to be decided by the bytes therefore has to write its own equals and hashCode, and a Scala 3 enum case cannot have a body to write them in. So the cases are ordinary final case classes under a sealed trait, which pattern matching, construction (RequestBody.Json("…")) and exhaustivity checking all see exactly as they saw the enum's cases. What is lost is ordinal and the scala.reflect.Enum supertype, which nothing uses.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Binary
object Empty
class Json
class Multipart
class Text
In this article