aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorAdam Warski <adam@warski.org>2017-09-07 09:13:04 +0200
committerGitHub <noreply@github.com>2017-09-07 09:13:04 +0200
commit3c85a4a5acf7197c1822d4b6339168e36cf1b853 (patch)
tree6147dd38662760d14bc6161b692486e1f29f9b30 /README.md
parent7188ebe102803c7d27c75b4640ded86a2ba7c6f6 (diff)
parent6874e55a316e4fe8a650efd3a849814a91bba8cb (diff)
downloadsttp-3c85a4a5acf7197c1822d4b6339168e36cf1b853.tar.gz
sttp-3c85a4a5acf7197c1822d4b6339168e36cf1b853.tar.bz2
sttp-3c85a4a5acf7197c1822d4b6339168e36cf1b853.zip
Merge pull request #28 from bhop/feature/request-timeout
Make request timeout configurable
Diffstat (limited to 'README.md')
-rw-r--r--README.md31
1 files changed, 26 insertions, 5 deletions
diff --git a/README.md b/README.md
index 336c9e7..84b70b1 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@ val query = "http language:scala"
// `sort` is removed, as the value is not defined
val request = sttp.get(uri"https://api.github.com/search/repositories?q=$query&sort=$sort")
-implicit val handler = HttpURLConnectionHandler
+implicit val handler = HttpURLConnectionHandler()
val response = request.send()
// response.header(...): Option[String]
@@ -61,7 +61,7 @@ experimenting with sttp by copy-pasting the following:
```scala
import $ivy.`com.softwaremill.sttp::core:0.0.11`
import com.softwaremill.sttp._
-implicit val handler = HttpURLConnectionHandler
+implicit val handler = HttpURLConnectionHandler()
sttp.get(uri"http://httpbin.org/ip").send()
```
@@ -113,7 +113,7 @@ value of type `SttpHandler` needs to be in scope to invoke the `send()` on the
request:
```scala
-implicit val handler = HttpURLConnectionHandler
+implicit val handler = HttpURLConnectionHandler()
val response: Response[String] = request.send()
```
@@ -214,7 +214,7 @@ in the identity type constructor, which is equivalent to no wrapper at all.
To use, add an implicit value:
```scala
-implicit val sttpHandler = HttpURLConnectionHandler
+implicit val sttpHandler = HttpURLConnectionHandler()
```
### `AkkaHttpHandler`
@@ -417,7 +417,7 @@ a request to decode the response to a specific object.
import com.softwaremill.sttp._
import com.softwaremill.sttp.circe._
-implicit val handler = HttpURLConnectionHandler
+implicit val handler = HttpURLConnectionHandler()
// Assume that there is an implicit circe encoder in scope
// for the request Payload, and a decoder for the Response
@@ -461,6 +461,26 @@ There are two type aliases for the request template that are used:
* `type Request[T, S] = RequestT[Id, T, S]`. A sendable request.
* `type PartialRequest[T, S] = RequestT[Empty, T, S]`
+## Timeouts
+
+Sttp supports read and connection timeouts:
+ * Connection timeout - can be set globally (30 seconds by default)
+ * Read timeout - can be set per request (1 minute by default)
+
+How to use:
+```scala
+import com.softwaremill.sttp._
+import scala.concurrent.duration._
+
+// all backends provide a constructor that allows users to specify connection timeout
+implicit val handler = HttpURLConnectionHandler(connectionTimeout = 1.minute)
+
+sttp
+ .get(uri"...")
+ .readTimeout(5.minutes) // or Duration.Inf to turn read timeout off
+ .send()
+```
+
## Notes
* the encoding for `String`s defaults to `utf-8`.
@@ -493,3 +513,4 @@ and pick a task you'd like to work on!
* [Omar Alejandro Mainegra Sarduy](https://github.com/omainegra)
* [Bjørn Madsen](https://github.com/aeons)
* [Piotr Buda](https://github.com/pbuda)
+* [Piotr Gabara](https://github.com/bhop)