Last active
May 25, 2024 08:38
-
-
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/ce0f9006cd70e9fbb26f781e731c933a9667fb4c
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
// 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 NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// 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