Skip to content

Instantly share code, notes, and snippets.

@tomatophobia
Last active May 25, 2021 00:49
Show Gist options
  • Save tomatophobia/408ddb1fb97e9dfa2d5daef40594bca1 to your computer and use it in GitHub Desktop.
Save tomatophobia/408ddb1fb97e9dfa2d5daef40594bca1 to your computer and use it in GitHub Desktop.
package com.example.quickstart
import cats.effect.Sync
import cats.implicits._
import org.http4s.HttpRoutes
import org.http4s.dsl.Http4sDsl
object QuickstartRoutes {
def jokeRoutes[F[_]: Sync](J: Jokes[F]): HttpRoutes[F] = {
val dsl = new Http4sDsl[F]{}
import dsl._
HttpRoutes.of[F] {
case GET -> Root / "joke" =>
for {
joke <- J.get
resp <- Ok(joke)
} yield resp
}
}
def helloWorldRoutes[F[_]: Sync](H: HelloWorld[F]): HttpRoutes[F] = {
val dsl = new Http4sDsl[F]{}
import dsl._
HttpRoutes.of[F] {
case GET -> Root / "hello" / name =>
for {
greeting <- H.hello(HelloWorld.Name(name))
resp <- Ok(greeting)
} yield resp
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment