0

I can't found a solution, how to build this uri

import org.http4s._
import org.http4s.implicits.http4sLiteralsSyntax

val uriFoll: Uri = uri"https://www.instagram.com/graphql/query/?query_hash=c76146de99bb02f6415203be841dd25a&variables={"id":"374397360","include_reel":false,"fetch_mutual":false,"first":24}"
Aleksey N Yakushev
  • 443
  • 1
  • 3
  • 11

2 Answers2

2

In general GET variables should be URL Encoded (https://www.w3schools.com/tags/ref_urlencode.ASP) so it probably should be:

val uriFoll: Uri = uri"https://www.instagram.com/graphql/query/?query_hash=c76146de99bb02f6415203be841dd25a&variables=%7B%22id%22%3A%22374397360%22%2C%22include_reel%22%3Afalse%2C%22fetch_mutual%22%3Afalse%2C%22first%22%3A24%7D"
AndyB
  • 490
  • 1
  • 4
  • 7
1

Solution

val vars: String = "{\"id\":\"374397360\",\"include_reel\":false,\"fetch_mutual\":false,\"first\":24}"
val varsEncoded: String = Uri.encode(vars)
val uriFoll: Uri = Uri.unsafeFromString(s"https://www.instagram.com/graphql/query/?query_hash=c76146de99bb02f6415203be841dd25a&variables=$varsEncoded")
Aleksey N Yakushev
  • 443
  • 1
  • 3
  • 11
  • 1
    If you don't care about compile time verification of whole URL, then probably this solution is a bit cleaner: `val uriFoll: Uri = uri"https://www.instagram.com/graphql/query/" .withQueryParam("query_hash", "c76146de99bb02f6415203be841dd25a") .withQueryParam("variables", """{"id":"374397360","include_reel":false,"fetch_mutual":false,"first":24}""")` – AndyB Sep 22 '20 at 20:51