Skip to content

Commit

Permalink
Update the sttp example so that it compiles using v3 (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw authored Feb 26, 2022
1 parent 0aa7e88 commit 11a9787
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,20 +615,16 @@ httpClient.expect[String](request)
```
```scala
// sttp
import com.softwaremill.sttp._
import sttp.client3._

val sort: Option[String] = None
val query = "http language:scala"
val request = basicRequest.response(asStringAlways)
.get(uri"https://api.github.com/search"
.addParams(Map("q" -> "http language:scala", "sort" -> "stars")))

// the `query` parameter is automatically url-encoded
// `sort` is removed, as the value is not defined
val request = sttp.get(uri"https://api.github.com/search/repositories?q=$query&sort=$sort")
val backend = HttpURLConnectionBackend()
val response = backend.send(request)

implicit val backend = HttpURLConnectionBackend()
val response = request.send()

// response.unsafeBody: by default read into a String
println(response.unsafeBody)
println(response.body)
```
```scala
// Dispatch
Expand Down

0 comments on commit 11a9787

Please sign in to comment.