Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: adding client docs #39

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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