http4s using double quotes and braces in uri

399 Views Asked by At

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}"
2

There are 2 best solutions below

1
On

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")
0
On

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"