Skip to content

Instantly share code, notes, and snippets.

@trickster
Forked from dacr/tapir-zio-hello-world-1.sc
Last active September 22, 2022 05:04
Show Gist options
  • Save trickster/f8b6caf2531f86df3a570f2ee85c72c4 to your computer and use it in GitHub Desktop.
Save trickster/f8b6caf2531f86df3a570f2ee85c72c4 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/13816f2c088ef3450ae06339d4a9b4f6a5f653ce
// summary : hello world http server (zhttp zio based) using tapir
// keywords : scala, zio, tapir, http, zhttp, endpoints, @testable
// publish : gist
// authors : David Crosson
// license : Apache
// 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.2.0"
//> using lib "com.softwaremill.sttp.tapir::tapir-core:1.1.0"
//> using lib "com.softwaremill.sttp.tapir::tapir-zio-http-server:1.1.0"
//> using lib "fr.janalyse::zio-worksheet:2.0.2.0"
// ---------------------
import sttp.tapir.ztapir.*
import sttp.tapir.server.ziohttp.ZioHttpInterpreter
import zio.*, zio.worksheet.*
/*
curl http://127.0.0.1:8080/hello
*/
val helloEndPoint = endpoint.in("hello").out(stringBody)
val helloRoute:ZServerEndpoint[Any, Any] = helloEndPoint.zServerLogic(_ => ZIO.succeed("Hello world"))
val helloHttp = ZioHttpInterpreter().toHttp(helloRoute)
zhttp.service.Server.start(8080, helloHttp).unsafeRun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment