-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate servers from tapir-loom (#3304)
- Loading branch information
1 parent
121cd6f
commit 4772b97
Showing
26 changed files
with
867 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Running as a Helidon Níma server | ||
|
||
```eval_rst | ||
.. note:: | ||
Helidon Níma requires JDK supporting Project Loom threading (JDK21 or newer). | ||
``` | ||
|
||
To expose an endpoint as a [Helidon Níma](https://helidon.io/nima) server, first add the following | ||
dependency: | ||
|
||
```scala | ||
"com.softwaremill.sttp.tapir" %% "tapir-nima-server" % "@VERSION@" | ||
``` | ||
|
||
Loom-managed concurrency uses direct style instead of effect wrappers like `Future[T]` or `IO[T]`. Because of this, | ||
Tapir endpoints defined for Nima server use `Id[T]`, which provides compatibility, while effectively means just `T`. | ||
|
||
Such endpoints are then processed through `NimaServerInterpreter` in order to obtain an `io.helidon.webserver.http.Handler`: | ||
|
||
```scala | ||
import io.helidon.webserver.WebServer | ||
import sttp.tapir._ | ||
import sttp.tapir.server.nima.{Id, NimaServerInterpreter} | ||
|
||
val helloEndpoint = endpoint.get | ||
.in("hello") | ||
.out(stringBody) | ||
.serverLogicSuccess[Id] { _ => | ||
Thread.sleep(1000) | ||
"hello, world!" | ||
} | ||
|
||
val handler = NimaServerInterpreter().toHandler(List(helloEndpoint)) | ||
|
||
WebServer | ||
.builder() | ||
.routing { builder => | ||
builder.any(handler) | ||
() | ||
} | ||
.port(8080) | ||
.build() | ||
.start() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.