Skip to content

Instantly share code, notes, and snippets.

@j-thepac
Last active August 18, 2022 10:37
Show Gist options
  • Save j-thepac/addaeb6db8fb6e7a44bb2ca8c57c6ce0 to your computer and use it in GitHub Desktop.
Save j-thepac/addaeb6db8fb6e7a44bb2ca8c57c6ce0 to your computer and use it in GitHub Desktop.
Run Http Client in spark REPL for Scala

HttpClient in spark-shell REPL

  • open link https://mvnrepository.com/artifact/com.softwaremill.sttp.client3/core

  • open compatible scalalink

  • click on Maven tab

  • copy groupId:artifactId:version ie., com.softwaremill.sttp.client3:core_2.12:3.7.4

  • create packagename as below

  • Open terminal and run below commands :

    $spark-shell --packages com.softwaremill.sttp.client3:core_2.12:3.7.4
    
    scala> import sttp.client3._
    import sttp.client3._
    
    scala> implicit val backend = HttpURLConnectionBackend()
    backent: sttp.client.SttpBackend[sttp.client.Identity,Nothing,sttp.client.NothingT] = sttp.client.FollowRedirectsBackend@50bac431
    
    scala> val r = basicRequest.get(uri"https://pokeapi.co/api/v2/pokemon/ditto").send(backend)
    r: sttp.client.Identity[sttp.client.Response[Either[String,String]]] = Response(Right({"ab....
    
    scala> println(r)
    Response(Right({"abilities":[{"ability":{"name":"limber
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment