Skip to content

Commit

Permalink
Merge pull request #732 from gaeljw/patch-1
Browse files Browse the repository at this point in the history
[doc] How to plug Tapir into existing Play app
  • Loading branch information
adamw authored Sep 1, 2020
2 parents 567c05a + 8d1aa1c commit e2ac7ba
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion generated-doc/out/server/play.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
```
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e2ac7ba

Please sign in to comment.