Skip to content

Commit 9404359

Browse files
committed
Fix docs
1 parent 4d56e0e commit 9404359

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

generated-doc/out/client/play.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Using as a Play client
2+
3+
Add the dependency:
4+
5+
```scala
6+
"com.softwaremill.sttp.tapir" %% "tapir-play-client" % "0.17.0-M6"
7+
```
8+
9+
To make requests using an endpoint definition using the [play client](https://github.com/playframework/play-ws), import:
10+
11+
```scala
12+
import sttp.tapir.client.play._
13+
```
14+
15+
This adds the two extension methods to any `Endpoint`:
16+
- `toPlayRequestUnsafe(String)`: given the base URI returns a function,
17+
which will generate a request and a response parser which might throw
18+
an exception when decoding of the result fails
19+
```scala
20+
I => (StandaloneWSRequest, StandaloneWSResponse => Either[E, O])
21+
```
22+
- `toPlayRequest(String)`: given the base URI returns a function,
23+
which will generate a request and a response parser which represents
24+
decoding errors as the `DecodeResult` class
25+
```scala
26+
I => (StandaloneWSRequest, StandaloneWSResponse => DecodeResult[Either[E, O]])
27+
```
28+
29+
Note that these are a one-argument functions, where the single argument is the input of end endpoint. This might be a
30+
single type, a tuple, or a case class, depending on the endpoint description.
31+
32+
After providing the input parameters, the two following are returned:
33+
- a description of the request to be made, with the input value
34+
encoded as appropriate request parameters: path, query, headers and body.
35+
This can be further customised and sent using regular Play methods.
36+
- a response parser to be applied to the response got after executing the request.
37+
The result will then contain the decoded error or success values
38+
(note that this can be the body enriched with data from headers/status code).
39+
40+
Example:
41+
42+
```scala
43+
import sttp.tapir._
44+
import sttp.tapir.client.play._
45+
import sttp.capabilities.akka.AkkaStreams
46+
47+
import scala.concurrent.ExecutionContext.Implicits.global
48+
import scala.concurrent.Future
49+
50+
import play.api.libs.ws.StandaloneWSClient
51+
52+
def example[I, E, O, R >: AkkaStreams](implicit wsClient: StandaloneWSClient) {
53+
val e: Endpoint[I, E, O, R] = ???
54+
val inputArgs: I = ???
55+
56+
val (req, responseParser) = e
57+
.toPlayRequestUnsafe(s"http://localhost:9000")
58+
.apply(inputArgs)
59+
60+
val result: Future[Either[E, O]] = req
61+
.execute()
62+
.map(responseParser)
63+
}
64+
```
65+
66+
## Limitations
67+
68+
Multipart requests are not supported.
69+
70+
Streaming capabilities:
71+
- only `AkkaStreams` is supported

generated-doc/out/client/sttp.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Using as an sttp client
2+
3+
Add the dependency:
4+
5+
```scala
6+
"com.softwaremill.sttp.tapir" %% "tapir-sttp-client" % "0.17.0-M6"
7+
```
8+
9+
To make requests using an endpoint definition using the [sttp client](https://github.com/softwaremill/sttp), import:
10+
11+
```scala
12+
import sttp.tapir.client.sttp._
13+
```
14+
15+
This adds the two extension methods to any `Endpoint`:
16+
- `toSttpRequestUnsafe(Uri)`: given the base URI returns a function, which might throw an exception if
17+
decoding of the result fails
18+
```scala
19+
I => Request[Either[E, O], Any]
20+
```
21+
- `toSttpRequest(Uri)`: given the base URI returns a function, which represents decoding errors as the `DecodeResult`
22+
class
23+
```scala
24+
I => Request[DecodeResult[Either[E, O]], Any]
25+
```
26+
27+
Note that these are a one-argument functions, where the single argument is the input of end endpoint. This might be a
28+
single type, a tuple, or a case class, depending on the endpoint description.
29+
30+
After providing the input parameters, a description of the request to be made is returned, with the input value
31+
encoded as appropriate request parameters: path, query, headers and body. This can be further
32+
customised and sent using any sttp backend. The response will then contain the decoded error or success values
33+
(note that this can be the body enriched with data from headers/status code).
34+
35+
See the [runnable example](https://github.com/softwaremill/tapir/blob/master/examples/src/main/scala/sttp/tapir/examples/BooksExample.scala)
36+
for example usage.
37+
38+
## Web sockets
39+
40+
To interpret a web socket enddpoint, an additional streams-specific import is needed, so that the interpreter can
41+
convert sttp's `WebSocket` instance into a pipe. This logic is looked up via the `WebSocketToPipe` implicit.
42+
43+
The required imports are as follows:
44+
45+
```scala
46+
import sttp.tapir.client.sttp.ws.akkahttp._ // for akka-streams // for akka-streams
47+
import sttp.tapir.client.sttp.ws.fs2._ // for fs2
48+
```
49+
50+
No additional dependencies are needed, as both of the above implementations are included in the main interpreter,]
51+
with dependencies on akka-streams and fs2 being marked as optional (hence these are not transitive).

0 commit comments

Comments
 (0)