Skip to content

Commit

Permalink
feat: tweaking the search-api API paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jachro committed Feb 12, 2024
1 parent 866e59c commit 63fe6fa
Showing 1 changed file with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.http4s.{HttpApp, HttpRoutes, Response}
import sttp.tapir.*
import sttp.tapir.server.ServerEndpoint
import sttp.tapir.server.http4s.Http4sServerInterpreter
import sttp.tapir.swagger.SwaggerUIOptions
import sttp.tapir.swagger.bundle.SwaggerInterpreter

object HttpApplication:
Expand All @@ -42,32 +43,42 @@ class HttpApplication[F[_]: Async](searchApi: SearchApi[F])
extends Http4sDsl[F]
with TapirBorerJson:

private val businessRoot = "search"

lazy val router: HttpApp[F] =
Router[F]("/" -> routes).orNotFound
Router[F](
s"/$businessRoot" -> businessRoutes,
"/" -> operationsRoutes
).orNotFound

private lazy val routes: HttpRoutes[F] =
Http4sServerInterpreter[F]().toRoutes(endpoints ::: swaggerEndpoints)
private lazy val businessRoutes: HttpRoutes[F] =
Http4sServerInterpreter[F]().toRoutes(swaggerEndpoints ::: businessEndpoints)

private lazy val endpoints: List[ServerEndpoint[Any, F]] =
private lazy val businessEndpoints: List[ServerEndpoint[Any, F]] =
List(
searchEndpoint.serverLogic(searchApi.find),
pingEndpoint.serverLogic[F](_ => "pong".asRight[Unit].pure[F])
searchEndpoint.serverLogic(searchApi.find)
)

private lazy val searchEndpoint: PublicEndpoint[String, String, List[Project], Any] =
val query =
path[String].name("user query").description("User defined query e.g. renku~")
endpoint.get
.in("api" / query)
.in(query)
.errorOut(borerJsonBody[String])
.out(borerJsonBody[List[Project]])
.description("Search API for searching Renku entities")

private lazy val pingEndpoint: PublicEndpoint[Unit, Unit, String, Any] =
private lazy val swaggerEndpoints =
SwaggerInterpreter(
swaggerUIOptions = SwaggerUIOptions.default.copy(contextPath = List(businessRoot))
).fromServerEndpoints[F](businessEndpoints, "Search API", "0.0.1")

private lazy val operationsRoutes: HttpRoutes[F] =
Http4sServerInterpreter[F]().toRoutes(List(pingEndpoint))

private lazy val pingEndpoint =
endpoint.get
.in("ping")
.out(stringBody)
.description("Ping")

private lazy val swaggerEndpoints =
SwaggerInterpreter().fromServerEndpoints[F](endpoints, "Search API", "0.0.1")
.serverLogic[F](_ => "pong".asRight[Unit].pure[F])

0 comments on commit 63fe6fa

Please sign in to comment.