Skip to content

Commit

Permalink
docs(#38): adding client docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MoeQuadrat committed Sep 16, 2022
1 parent 80bdce6 commit 241e869
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
30 changes: 27 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ build.sbt

**Usage**
---
- define controllers in smithy files
- use smithy4s codegen (sbt compile)

- define your controller in smithy files
- generate your scala files (sbt compile)
- create Controller Scala Class
Server
- create controller scala class
- extend your Controller with the generated Scala Type and smithy4play Type ContextRoute

```scala
Expand All @@ -49,8 +50,31 @@ class PreviewController @Inject(
EitherT.rightT[Future, ContextRouteError](PreviewResponse(Some("Hello")))
}
}
```
Client
- create Client Class
- extend the Client with the generated Scala Type and smithy4play Type ClientResponse
- implement a smithy4play RequestClient that handles the request

```scala
class PreviewControllerClient(
additionalHeaders: Map[String, Seq[String]] = Map.empty,
baseUri: String = "/")
(implicit ec: ExecutionContext, client: RequestClient)
extends PreviewControllerService[ClientResponse] {

val smithyPlayClient = new SmithyPlayClient(baseUri, TestControllerService.service)

override def preview(): ClientResponse[SimpleTestResponse] =
smithyPlayClient.send(PreviewControllerServiceGen.Preview(), Some(additionalHeaders))
}
```
now the methods from the client can be accessed like this:
```scala
val previewControllerClient = new PreviewControllerClient()
previewControllerClient.preview()
```
For a further examples take a look at the smithy4playTest project.

**Routing**
---
Expand Down
9 changes: 6 additions & 3 deletions smithy4playTest/test/TestControllerClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import testDefinitions.test.{
import scala.concurrent.ExecutionContext

class TestControllerClient(additionalHeaders: Map[String, Seq[String]] = Map.empty, baseUri: String = "/")(implicit
ec: ExecutionContext,
client: RequestClient
ec: ExecutionContext,
client: RequestClient
) extends TestControllerService[ClientResponse] {

val smithyPlayClient = new SmithyPlayClient(baseUri, TestControllerService.service)
Expand All @@ -39,7 +39,10 @@ class TestControllerClient(additionalHeaders: Map[String, Seq[String]] = Map.emp
smithyPlayClient.send(TestControllerServiceGen.Health(), Some(additionalHeaders))

override def testWithBlob(body: ByteArray, contentType: String): ClientResponse[BlobResponse] =
smithyPlayClient.send(TestControllerServiceGen.TestWithBlob(BlobRequest(body, contentType)), Some(additionalHeaders))
smithyPlayClient.send(
TestControllerServiceGen.TestWithBlob(BlobRequest(body, contentType)),
Some(additionalHeaders)
)

override def testWithQuery(testQuery: String): ClientResponse[Unit] =
smithyPlayClient.send(TestControllerServiceGen.TestWithQuery(QueryRequest(testQuery)), Some(additionalHeaders))
Expand Down

0 comments on commit 241e869

Please sign in to comment.