clue.js.FetchJSClient.scala Maven / Gradle / Ivy
// Copyright (c) 2016-2023 Association of Universities for Research in Astronomy, Inc. (AURA)
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause
package clue.js
import cats.Applicative
import cats.MonadThrow
import clue.FetchClientImpl
import org.scalajs.dom.Headers
import org.typelevel.log4cats.Logger
object FetchJSClient {
def of[F[_], S](uri: String, name: String = "", headers: Headers = new Headers())(implicit
F: MonadThrow[F],
backend: FetchJSBackend[F],
logger: Logger[F]
): F[FetchJSClient[F, S]] = {
val logPrefix = s"clue.FetchJSClient[${if (name.isEmpty) uri else name}]"
val internalLogger = logger.withModifiedString(s => s"$logPrefix $s")
Applicative[F].pure(
new FetchClientImpl[F, FetchJSRequest, S](
FetchJSRequest(uri, headers)
)(F, internalLogger, backend)
)
}
}