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

io.hireproof.structure.Routes.scala Maven / Gradle / Ivy

The newest version!
package io.hireproof.structure

import cats.data.Chain

final case class Routes[F[_]] private (toChain: Chain[Endpoint.Implementation[F, _, _]]) {
  def find(request: Request): Option[Endpoint.Implementation[F, _, _]] = toChain.find(_.endpoint.input.matches(request))

  def ~(endpoint: Endpoint.Implementation[F, _, _]): Routes[F] = Routes(toChain :+ endpoint)

  def ++(routes: Routes[F]): Routes[F] = Routes(toChain ++ routes.toChain)
}

object Routes {
  def fromChain[F[_]](endpoints: Chain[Endpoint.Implementation[F, _, _]]): Routes[F] = Routes(endpoints)

  def fromSeq[F[_]](endpoints: Seq[Endpoint.Implementation[F, _, _]]): Routes[F] = fromChain(Chain.fromSeq(endpoints))

  def apply[F[_]](endpoints: Endpoint.Implementation[F, _, _]*): Routes[F] = fromSeq(endpoints)

  def one[F[_]](endpoint: Endpoint.Implementation[F, _, _]): Routes[F] = fromChain(Chain.one(endpoint))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy