Skip to content

Instantly share code, notes, and snippets.

@joshuakfarrar
Created January 22, 2018 14:54
Show Gist options
  • Save joshuakfarrar/d50f7744497a88c91d2687d773732915 to your computer and use it in GitHub Desktop.
Save joshuakfarrar/d50f7744497a88c91d2687d773732915 to your computer and use it in GitHub Desktop.
package me.sent1nel
import cats.effect.IO
import io.circe.{Json, Encoder}
import org.http4s.HttpService
import org.http4s.dsl.Http4sDsl
import org.http4s.server.blaze.BlazeBuilder
import org.http4s.util.StreamApp
import org.http4s.circe._
import io.circe._, io.circe.generic.auto._, io.circe.syntax._
object App extends StreamApp[IO] with Http4sDsl[IO] {
implicit val StatusEncoder: Encoder[StatusMessage] =
Encoder.forProduct2("message", "statusCode")(s => (s.message, s.statusCode))
case class StatusMessage(message: String, statusCode: Int)
val service = HttpService[IO] {
case GET -> Root / "status" =>
Ok(StatusMessage("ok", 200).asJson)
}
def stream(args: List[String], requestShutdown: IO[Unit]) =
BlazeBuilder[IO]
.bindHttp(8080, "0.0.0.0")
.mountService(service, "/api/v1")
.serve
}
@joshuakfarrar
Copy link
Author

import io.circe.{Decoder, Encoder, Json}

object Events {
  def payload(user: User, events: Seq[Event]): Json =
    Json.obj(
      "@context" -> json"""
      {
        "date": "http://www.w3.org/2001/XMLSchema#date",
        "duration": {
          "@type": "http://schema.org/Duration"
        }
      }
      """,
      "user" -> user.asJson,
      "events" -> Json.arr(events.map(_.asJson): _*)
    )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment