Skip to content
forked from zio/zio-http

A next-generation Scala framework for building scalable, correct, and efficient HTTP clients and servers

License

Notifications You must be signed in to change notification settings

hochgi/zio-http

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ZIO Http

ZIO HTTP is a scala library for building http apps. It is powered by ZIO and Netty and aims at being the defacto solution for writing, highly scalable and performant web applications using idiomatic Scala.

Development CI Badge Sonatype Releases Sonatype Snapshots javadoc ZIO Http

Installation

Setup via build.sbt:

libraryDependencies += "dev.zio" %% "zio-http" % "3.0.0-RC6"

NOTES ON VERSIONING:

  • Older library versions 1.x or 2.x with organization io.d11 of ZIO Http are derived from Dream11, the organization that donated ZIO Http to the ZIO organization in 2022.
  • Newer library versions, starting in 2023 and resulting from the ZIO organization started with 0.0.x, reaching 1.0.0 release candidates in April of 2023

Getting Started

ZIO HTTP provides a simple and expressive API for building HTTP applications. It supports both server and client-side APIs.

ZIO HTTP is designed in terms of HTTP as function, where both server and client are a function from Request to Response.

Greeting Server

The following example demonstrates how to build a simple greeting server. It contains 2 routes: one on the root path, it responds with a fixed string, and one route on the path /greet that responds with a greeting message based on the query parameter name.

import zio._
import zio.http._

object GreetingServer extends ZIOAppDefault {
  val routes =
    Routes(
      Method.GET / Root -> handler(Response.text("Greetings at your service")),
      Method.GET / "greet" -> handler { (req: Request) =>
        val name = req.queryParamToOrElse("name", "World")
        Response.text(s"Hello $name!")
      }
    )

  def run = Server.serve(routes).provide(Server.default)
}

Greeting Client

The following example demonstrates how to call the greeting server using the ZIO HTTP client:

import zio._
import zio.http._

object GreetingClient extends ZIOAppDefault {

  val app =
    for {
      client   <- ZIO.serviceWith[Client](_.host("localhost").port(8080))
      request  =  Request.get("greet").addQueryParam("name", "John")
      response <- client.request(request)
      _        <- response.body.asString.debug("Response")
    } yield ()

  def run = app.provide(Client.default, Scope.default)
}

Documentation

Learn more on the ZIO Http homepage!

Contributing

For the general guidelines, see ZIO contributor's guide.

Code of Conduct

See the Code of Conduct

Support

Come chat with us on Badge-Discord.

License

License

About

A next-generation Scala framework for building scalable, correct, and efficient HTTP clients and servers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Scala 99.8%
  • Other 0.2%