0
votes

I'm trying to build Uri, but Query method gives me type mismatch, expected string, actual Uri.Query

def buildUri(url: String, query: Option[Map[String, String]] = None): Uri = {

    val fullUrl = endpoint + (if (endpoint.endsWith("/")) url else "/" + url)

    val uri: Uri = query match {
      case Some(map) if map.nonEmpty =>
        Uri(fullUrl.toString).copy(query = Query(map))
      case _ =>
        Uri(fullUrl.toString)
    }

    uri

  }
1
Uri case class doesn't has any parameter named query as i can see. Uri(scheme: String, authority: Authority, path: Path, rawQueryString: Option[String], fragment: Option[String])Raman Mishra
There is object Queri insideifog
Query not query and you are assiging value to query it doesn't has any parameter named query and yes it has Query. what you exactly want to do?Raman Mishra

1 Answers

1
votes

I think this is what you want to do:

def buildUri(url: String, query: Option[Map[String, String]] = None): Uri = {

    val fullUrl = endpoint + (if (endpoint.endsWith("/")) url else "/" + url)

    val uri: Uri = query match {
      case Some(map) if map.nonEmpty =>
        Uri(fullUrl.toString).withQuery(query = Query(map))
      case _ =>
        Uri(fullUrl.toString)
    }

    uri
  }