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

scala-sttp.requests.mustache Maven / Gradle / Ivy

There is a newer version: 7.8.0
Show newest version
{{>licenseInfo}}
package {{mainPackage}}.core

import sttp.client.{Identity, RequestT, ResponseError}

/**
 * This trait needs to be added to any model defined by the api.
 */
trait ApiModel

/**
 * Sttp type aliases
 */
object alias {
  type ApiRequestT[T] = RequestT[Identity, Either[ResponseError[Exception], T], Nothing]
}

/**
 * Single trait defining a credential that can be transformed to a paramName / paramValue tupple
 */
sealed trait Credentials {
  def asQueryParam: Option[(String, String)] = None
}

sealed case class BasicCredentials(user: String, password: String) extends Credentials

sealed case class BearerToken(token: String) extends Credentials

sealed case class ApiKeyCredentials(key: ApiKeyValue, keyName: String, location: ApiKeyLocation) extends Credentials {
  override def asQueryParam: Option[(String, String)] = location match {
    case ApiKeyLocations.QUERY => Some((keyName, key.value))
    case _ => None
  }
}

sealed case class ApiKeyValue(value: String)

sealed trait ApiKeyLocation

object ApiKeyLocations {

  case object QUERY extends ApiKeyLocation

  case object HEADER extends ApiKeyLocation

  case object COOKIE extends ApiKeyLocation

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy