diff --git a/readme.md b/readme.md index cc56ab0a..14d54bd2 100644 --- a/readme.md +++ b/readme.md @@ -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 @@ -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** --- diff --git a/smithy4playTest/test/TestControllerClient.scala b/smithy4playTest/test/TestControllerClient.scala index 35620b99..cfb0bdf9 100644 --- a/smithy4playTest/test/TestControllerClient.scala +++ b/smithy4playTest/test/TestControllerClient.scala @@ -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) @@ -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))