1
package hammock
2

3
import cats._
4
import cats.free._
5

6
sealed trait HttpF[A] {
7
  def req: HttpRequest
8
}
9

10
final case class Options(req: HttpRequest) extends HttpF[HttpResponse]
11
final case class Get(req: HttpRequest)     extends HttpF[HttpResponse]
12
final case class Head(req: HttpRequest)    extends HttpF[HttpResponse]
13
final case class Post(req: HttpRequest)    extends HttpF[HttpResponse]
14
final case class Put(req: HttpRequest)     extends HttpF[HttpResponse]
15
final case class Delete(req: HttpRequest)  extends HttpF[HttpResponse]
16
final case class Trace(req: HttpRequest)   extends HttpF[HttpResponse]
17
final case class Patch(req: HttpRequest)   extends HttpF[HttpResponse]
18

19
object Ops {
20
  def options(uri: Uri, headers: Map[String, String]): Free[HttpF, HttpResponse] =
21 1
    Free.liftF(Options(HttpRequest(uri, headers, None)))
22
  def get(uri: Uri, headers: Map[String, String]): Free[HttpF, HttpResponse] =
23 1
    Free.liftF(Get(HttpRequest(uri, headers, None)))
24
  def head(uri: Uri, headers: Map[String, String]): Free[HttpF, HttpResponse] =
25 1
    Free.liftF(Head(HttpRequest(uri, headers, None)))
26
  def post(uri: Uri, headers: Map[String, String], entity: Option[Entity]): Free[HttpF, HttpResponse] =
27 1
    Free.liftF(Post(HttpRequest(uri, headers, entity)))
28
  def put(uri: Uri, headers: Map[String, String], entity: Option[Entity]): Free[HttpF, HttpResponse] =
29 1
    Free.liftF(Put(HttpRequest(uri, headers, entity)))
30
  def delete(uri: Uri, headers: Map[String, String]): Free[HttpF, HttpResponse] =
31 1
    Free.liftF(Delete(HttpRequest(uri, headers, None)))
32
  def trace(uri: Uri, headers: Map[String, String]): Free[HttpF, HttpResponse] =
33 1
    Free.liftF(Trace(HttpRequest(uri, headers, None)))
34
  def patch(uri: Uri, headers: Map[String, String], entity: Option[Entity]): Free[HttpF, HttpResponse] =
35 1
    Free.liftF(Patch(HttpRequest(uri, headers, entity)))
36
}
37

38
class HttpRequestC[F[_]](implicit I: InjectK[HttpF, F]) {
39
  def options(uri: Uri, headers: Map[String, String]): Free[F, HttpResponse] =
40 0
    Free.inject(Options(HttpRequest(uri, headers, None)))
41
  def get(uri: Uri, headers: Map[String, String]): Free[F, HttpResponse] =
42 0
    Free.inject(Get(HttpRequest(uri, headers, None)))
43
  def head(uri: Uri, headers: Map[String, String]): Free[F, HttpResponse] =
44 0
    Free.inject(Head(HttpRequest(uri, headers, None)))
45
  def post(uri: Uri, headers: Map[String, String], entity: Option[Entity]): Free[F, HttpResponse] =
46 0
    Free.inject(Post(HttpRequest(uri, headers, entity)))
47
  def put(uri: Uri, headers: Map[String, String], entity: Option[Entity]): Free[F, HttpResponse] =
48 0
    Free.inject(Put(HttpRequest(uri, headers, entity)))
49
  def delete(uri: Uri, headers: Map[String, String]): Free[F, HttpResponse] =
50 0
    Free.inject(Delete(HttpRequest(uri, headers, None)))
51
  def trace(uri: Uri, headers: Map[String, String]): Free[F, HttpResponse] =
52 0
    Free.inject(Trace(HttpRequest(uri, headers, None)))
53
  def patch(uri: Uri, headers: Map[String, String], entity: Option[Entity]): Free[F, HttpResponse] =
54 0
    Free.inject(Patch(HttpRequest(uri, headers, entity)))
55
}
56

57
object HttpRequestC {
58 0
  implicit def httpRequestC[F[_]](implicit I: InjectK[HttpF, F]): HttpRequestC[F] = new HttpRequestC[F]
59
}

Read our documentation on viewing source code .

Loading