From 8d1aa1c2195e50d29256292e2541f123207d0f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Jourdan-Weil?= Date: Mon, 31 Aug 2020 08:13:38 +0200 Subject: [PATCH] [doc] How to plug Tapir into existing Play app --- generated-doc/out/server/play.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/generated-doc/out/server/play.md b/generated-doc/out/server/play.md index d8893e148b..b37bf66f4b 100644 --- a/generated-doc/out/server/play.md +++ b/generated-doc/out/server/play.md @@ -4,7 +4,7 @@ To expose endpoint as a [play-server](https://www.playframework.com/) first add ```scala "com.softwaremill.sttp.tapir" %% "tapir-play-server" % "0.16.16" ``` -and +and (if you don't already depends on Play) ```scala "com.typesafe.play" %% "play-akka-http-server" % "2.8.2" ``` @@ -71,6 +71,10 @@ val anEndpoint: Endpoint[(String, Int), Unit, String, Nothing] = ??? val aRoute: Routes = anEndpoint.toRoute((logic _).tupled) ``` +## Bind the routes + +### Creating the HTTP server manually + An HTTP server can then be started as in the following example: ```scala @@ -92,6 +96,27 @@ object Main { } ``` +### As part of an existing Play application + +Or, if you already have an existing Play application, you can create a `Router` class and bind it to the application. + +First, add a line like following in the `routes` files: +``` +-> /api api.ApiRouter +``` +Then create a class like this: +```scala +class ApiRouter @Inject() () extends SimpleRouter { + override def routes: Routes = { + // Routes generated by Tapir (see above) + aRoute + .orElse(anotherRoute) + } +} +``` + +Find more details about how to bind a `Router` to your application in the [Play framework documentation](https://www.playframework.com/documentation/2.8.x/ScalaSirdRouter#Binding-sird-Router). + ## Configuration The interpreter can be configured by providing an implicit `PlayServerOptions` value and status mappers, see