From 5620043c1fc9fc846fa4a5fe91b2af7fb1ff6008 Mon Sep 17 00:00:00 2001 From: adamw Date: Mon, 9 Oct 2017 17:03:44 +0200 Subject: Backend stubs with fallback (thx to @gabro) --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'README.md') 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) -- cgit v1.2.3