All Downloads are FREE. Search and download functionalities are using the official Maven repository.

endpoints4s.fetch.JsonEntities.scala Maven / Gradle / Ivy

The newest version!
package endpoints4s.fetch

import endpoints4s.Codec
import endpoints4s.algebra
import org.scalajs.dom.{RequestInit => FetchRequestInit}

trait JsonEntitiesFromCodecs extends EndpointsWithCustomErrors with algebra.JsonEntitiesFromCodecs {

  def jsonRequest[A](implicit codec: JsonCodec[A]) =
    (a: A, requestInit: FetchRequestInit) => {
      requestInit.setRequestHeader("Content-Type", "application/json")
      requestInit.body = stringCodec(codec).encode(a)
    }

  def jsonResponse[A](implicit codec: JsonCodec[A]) =
    stringCodecResponse(stringCodec(codec))

}

trait JsonEntitiesFromSchemas
    extends algebra.JsonEntitiesFromSchemas
    with JsonEntitiesFromCodecs
    with endpoints4s.ujson.JsonSchemas {

  def stringCodec[A](implicit codec: JsonCodec[A]): Codec[String, A] =
    codec.stringCodec

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy