aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authoradamw <adam@warski.org>2017-10-09 17:03:44 +0200
committeradamw <adam@warski.org>2017-10-09 17:03:44 +0200
commit5620043c1fc9fc846fa4a5fe91b2af7fb1ff6008 (patch)
tree6cc71430df59ad68815352be26696b835e3354ac /README.md
parente093ee494d45350818933049c498ec5eb4fb98be (diff)
downloadsttp-5620043c1fc9fc846fa4a5fe91b2af7fb1ff6008.tar.gz
sttp-5620043c1fc9fc846fa4a5fe91b2af7fb1ff6008.tar.bz2
sttp-5620043c1fc9fc846fa4a5fe91b2af7fb1ff6008.zip
Backend stubs with fallback (thx to @gabro)
Diffstat (limited to 'README.md')
-rw-r--r--README.md18
1 files changed, 18 insertions, 0 deletions
diff --git a/README.md b/README.md
index 1adbbf6..336531c 100644
--- a/README.md
+++ b/README.md
@@ -560,6 +560,23 @@ However, this approach has one caveat: the responses are not type-safe. That
is, the backend cannot match on or verify that the type included in the
response matches the response type requested.
+It is also possible to create a stub backend which delegates calls to another
+(possibly "real") backend if none of the specified predicates match a request.
+This can be useful during development, to partially stub a yet incomplete
+API with which we integrate:
+
+```scala
+implicit val testingBackend = SttpBackendStub.withFallback(HttpURLConnectionBackend())
+ .whenRequestMatches(_.uri.path.startsWith(List("a")))
+ .thenRespond("I'm a STUB!")
+
+val response1 = sttp.get(uri"http://api.internal/a").send()
+// response1.body will be Right("I'm a STUB")
+
+val response2 = sttp.post(uri"http://api.internal/b").send()
+// response2 will be whatever a "real" network call to api.internal/b returns
+```
+
## Notes
* the encoding for `String`s defaults to `utf-8`.
@@ -593,3 +610,4 @@ and pick a task you'd like to work on!
* [Bjørn Madsen](https://github.com/aeons)
* [Piotr Buda](https://github.com/pbuda)
* [Piotr Gabara](https://github.com/bhop)
+* [Gabriele Petronella](https://github.com/gabro)