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

[doc] How to plug Tapir into existing Play app #732

Merged
merged 1 commit into from
Sep 1, 2020
Merged
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
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