Last active
February 3, 2026 20:22
-
-
Save dacr/10ea484261435d1a713f7ccc49ee7a09 to your computer and use it in GitHub Desktop.
hello world http server (zhttp zio based) using tapir / published by https://github.com/dacr/code-examples-manager #fd3e1ee8-afe4-4c3d-a9fe-5e0f16a985ad/b95a0685dd2ede8e187f97708d9e42bcc4125e00
This file contains hidden or 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
| // summary : hello world http server (zhttp zio based) using tapir | |
| // keywords : scala, zio, tapir, http, zhttp, endpoints, @testable, @exclusive | |
| // publish : gist | |
| // authors : David Crosson | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // id : fd3e1ee8-afe4-4c3d-a9fe-5e0f16a985ad | |
| // created-on : 2021-11-20T13:51:35+01:00 | |
| // managed-by : https://github.com/dacr/code-examples-manager | |
| // run-with : scala-cli $file | |
| // test-with : curl http://127.0.0.1:8080/hello | |
| // --------------------- | |
| //> using scala "3.4.2" | |
| //> using dep "com.softwaremill.sttp.tapir::tapir-core:1.6.0" | |
| //> using dep "com.softwaremill.sttp.tapir::tapir-zio-http-server:1.6.0" | |
| //> using dep "fr.janalyse::zio-worksheet:2.0.15.0" | |
| // --------------------- | |
| import sttp.tapir.ztapir.* | |
| import sttp.tapir.server.ziohttp.ZioHttpInterpreter | |
| import zio.*, zio.worksheet.*, zio.http.Server | |
| /* | |
| curl http://127.0.0.1:8080/hello | |
| */ | |
| val helloEndPoint = endpoint.in("hello").out(stringBody) | |
| val helloRoute = helloEndPoint.zServerLogic[Any]( _ => ZIO.succeed("Hello world")) | |
| val helloHttp = ZioHttpInterpreter().toHttp(helloRoute) | |
| Server.serve(helloHttp.withDefaultErrorResponse).provide(Server.default).unsafeRun |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment