-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1763 from softwaremill/default-backend
Introduce default backends
- Loading branch information
Showing
26 changed files
with
180 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
core/src/main/scalajs/sttp/client4/DefaultFutureBackend.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package sttp.client4 | ||
|
||
import sttp.client4.fetch.FetchBackend | ||
import sttp.client4.testing.WebSocketBackendStub | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
object DefaultFutureBackend { | ||
|
||
/** Creates a default websocket-capable backend which uses [[Future]] to represent side effects, with the given | ||
* `options`. Currently based on [[FetchBackend]]. | ||
*/ | ||
def apply()(implicit ec: ExecutionContext = ExecutionContext.global): WebSocketBackend[Future] = FetchBackend() | ||
|
||
/** Create a stub backend for testing, which uses [[Future]] to represent side effects, and doesn't support streaming. | ||
* | ||
* See [[WebSocketBackendStub]] for details on how to configure stub responses. | ||
*/ | ||
def stub(implicit ec: ExecutionContext = ExecutionContext.global): WebSocketBackendStub[Future] = | ||
WebSocketBackendStub.asynchronousFuture | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
core/src/main/scalajvm/sttp/client4/DefaultFutureBackend.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package sttp.client4 | ||
|
||
import sttp.client4.httpclient.HttpClientFutureBackend | ||
import sttp.client4.testing.WebSocketBackendStub | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
object DefaultFutureBackend { | ||
|
||
/** Creates a default websocket-capable backend which uses [[Future]] to represent side effects, with the given | ||
* `options`. Currently based on [[HttpClientFutureBackend]]. | ||
*/ | ||
def apply( | ||
options: BackendOptions = BackendOptions.Default | ||
)(implicit ec: ExecutionContext = ExecutionContext.global): WebSocketBackend[Future] = { | ||
HttpClientFutureBackend(options, identity, PartialFunction.empty) | ||
} | ||
|
||
/** Create a stub backend for testing, which uses [[Future]] to represent side effects, and doesn't support streaming. | ||
* | ||
* See [[WebSocketBackendStub]] for details on how to configure stub responses. | ||
*/ | ||
def stub(implicit ec: ExecutionContext = ExecutionContext.global): WebSocketBackendStub[Future] = | ||
WebSocketBackendStub.asynchronousFuture | ||
} |
16 changes: 16 additions & 0 deletions
16
core/src/main/scalajvm/sttp/client4/DefaultSyncBackend.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package sttp.client4 | ||
|
||
import sttp.client4.httpclient.HttpClientSyncBackend | ||
import sttp.client4.testing.SyncBackendStub | ||
|
||
object DefaultSyncBackend { | ||
|
||
/** Creates a default synchronous backend with the given `options`, which is currently based on | ||
* [[HttpClientSyncBackend]]. | ||
*/ | ||
def apply(options: BackendOptions = BackendOptions.Default): SyncBackend = | ||
HttpClientSyncBackend(options, identity, PartialFunction.empty) | ||
|
||
/** Create a stub backend for testing. See [[SyncBackendStub]] for details on how to configure stub responses. */ | ||
def stub: SyncBackendStub = SyncBackendStub | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
core/src/main/scalanative/sttp/client4/DefaultSyncBackend.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package sttp.client4 | ||
|
||
import sttp.client4.curl.CurlBackend | ||
import sttp.client4.testing.SyncBackendStub | ||
|
||
object DefaultSyncBackend { | ||
|
||
/** Creates a default synchronous backend, which is currently based on [[CurlBackend]]. */ | ||
def apply(): SyncBackend = CurlBackend() | ||
|
||
/** Create a stub backend for testing. See [[SyncBackendStub]] for details on how to configure stub responses. */ | ||
def stub: SyncBackendStub = SyncBackendStub | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.