All Projects → kovacshuni → zio-http4s-example

kovacshuni / zio-http4s-example

Licence: other
For anyone who's struggling to put an http4s server together with ZIO

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to zio-http4s-example

idealingua-v1
IdeaLingua RPC for Scala, TypeScript, C#, Go
Stars: ✭ 13 (-31.58%)
Mutual labels:  http4s, zio, cats-effect
classy-optics
🔎 Source code shown at my talks at Scale by the Bay 2018 and Scalar 2019
Stars: ✭ 25 (+31.58%)
Mutual labels:  http4s, zio, cats-effect
pfhais
Source code of the book Pure functional HTTP APIs in Scala including a chapter about upgrading to Scala 3.
Stars: ✭ 48 (+152.63%)
Mutual labels:  http4s, cats-effect
event-driven-messenger
No description or website provided.
Stars: ✭ 43 (+126.32%)
Mutual labels:  http4s, zio
Ddc
The Disco Discus Compiler
Stars: ✭ 164 (+763.16%)
Mutual labels:  functional, effects
zorechka-bot
Github bot for keeping your Bazel dependencies up-to-date and clean
Stars: ✭ 25 (+31.58%)
Mutual labels:  http4s, zio
Zio
ZIO — A type-safe, composable library for async and concurrent programming in Scala
Stars: ✭ 3,167 (+16568.42%)
Mutual labels:  effects, zio
tradeio
A disciplined way to purely functional domain models in Scala
Stars: ✭ 19 (+0%)
Mutual labels:  http4s, cats-effect
http4s-poc-api
POC: http4s http api on zio
Stars: ✭ 34 (+78.95%)
Mutual labels:  http4s, zio
influencer-stats
Playground for measuring performance of functional programming tools in Scala. Gathers statistics about videos.
Stars: ✭ 24 (+26.32%)
Mutual labels:  http4s, cats-effect
typelevel-stack.g8
📚 Unofficial Giter8 template for the Typelevel Stack (Http4s / Doobie / Circe / Cats Effect / Fs2) based on Cats v1.x.x
Stars: ✭ 63 (+231.58%)
Mutual labels:  http4s, cats-effect
spotify-next
Small CLI app for filtering out music on Spotify.
Stars: ✭ 45 (+136.84%)
Mutual labels:  http4s, cats-effect
tutorials
🎥 Source code of the examples shown in the video tutorials
Stars: ✭ 18 (-5.26%)
Mutual labels:  zio, cats-effect
scala-functional-programming-tutorial
Functional Programming in Scala Tutorial
Stars: ✭ 23 (+21.05%)
Mutual labels:  http4s, cats-effect
hookuspocus
hooks for all the functions!
Stars: ✭ 60 (+215.79%)
Mutual labels:  functional
vuepress-plugin-cursor-effects
🎉 Add a cute click effect to your mouse in your vuepress!
Stars: ✭ 18 (-5.26%)
Mutual labels:  effects
go-callbag
golang implementation of Callbag
Stars: ✭ 19 (+0%)
Mutual labels:  functional
razer-cli
CLI for configuring Razer devices
Stars: ✭ 46 (+142.11%)
Mutual labels:  effects
fs2-google-pubsub
Google Cloud Pub/Sub stream-based client built on top of cats-effect, fs2 and http4s.
Stars: ✭ 32 (+68.42%)
Mutual labels:  cats-effect
salt
The compilation target that functional programmers always wanted.
Stars: ✭ 62 (+226.32%)
Mutual labels:  functional

ZIO http4s Simple Example

Here's how to put toghether almost the simplest http4s server with ZIO.

Run:

sbt run

Try:

curl localhost:8080/hello

Dependencies:

"org.http4s" %% "http4s-blaze-server" % "1.0.0-M4",
"org.http4s" %% "http4s-dsl"          % "1.0.0-M4",
"dev.zio"    %% "zio"                 % "1.0.1",
"dev.zio"    %% "zio-interop-cats"    % "2.1.4.0"

Code:

package com.hunorkovacs.ziohttp4stry

import zio._
import zio.console._
import zio.interop.catz._
import zio.interop.catz.implicits._

import org.http4s._
import org.http4s.dsl.Http4sDsl
import org.http4s.implicits._
import org.http4s.server.blaze.BlazeServerBuilder

object Main extends App {

  private val dsl = Http4sDsl[Task]
  import dsl._

  private val helloWorldService = HttpRoutes
    .of[Task] {
      case GET -> Root / "hello" => Ok("Hello, Joe")
    }
    .orNotFound

  def run(args: List[String]): zio.URIO[zio.ZEnv, ExitCode] =
    ZIO
      .runtime[ZEnv]
      .flatMap { implicit runtime =>
        BlazeServerBuilder[Task](runtime.platform.executor.asEC)
          .bindHttp(8080, "localhost")
          .withHttpApp(helloWorldService)
          .resource
          .toManagedZIO
          .useForever
          .foldCauseM(
            err => putStrLn(err.prettyPrint).as(ExitCode.failure),
            _ => ZIO.succeed(ExitCode.success)
          )
      }

}

random keywords:

zio, instead of cats, cats-effect, final tagless, http4s, http server, managed, resource, effect tracking, typesafe, strongly typed, functional, monad

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].