Coder Social home page Coder Social logo

guptadeepak8 / zio-http Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zio/zio-http

0.0 0.0 0.0 6.54 MB

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

Home Page: https://zio.dev/zio-http

License: Apache License 2.0

Shell 0.12% Scala 99.83% Dockerfile 0.06%

zio-http's Introduction

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.

ZIO HTTP is designed in terms of HTTP as function, where both server and client are a function from a request to a response, with a focus on type safety, composability, and testability.

Development CI Badge Sonatype Releases Sonatype Snapshots javadoc ZIO Http

Some of the key features of ZIO HTTP are:

ZIO Native: ZIO HTTP is built atop ZIO, a type-safe, composable, and asynchronous effect system for Scala. It inherits all the benefits of ZIO, including testability, composability, and type safety.

Cloud-Native: ZIO HTTP is designed for cloud-native environments and supports building highly scalable and performant web applications. Built atop ZIO, it features built-in support for concurrency, parallelism, resource management, error handling, structured logging, configuration management, and metrics instrumentation.

Imperative and Declarative Endpoints: ZIO HTTP provides a declarative API for defining HTTP endpoints besides the imperative API. With imperative endpoints, both the shape of the endpoint and the logic are defined together, while with declarative endpoints, the description of the endpoint is separated from its logic. Developers can choose the style that best fit their needs.

Type-Driven API Design: Beside the fact that ZIO HTTP supports declarative endpoint descriptions, it also provides a type-driven API design that leverages Scala's type system to ensure correctness and safety at compile time. So the implementation of the endpoint is type-checked against the description of the endpoint.

Middleware Support: ZIO HTTP offers middleware support for incorporating cross-cutting concerns such as logging, metrics, authentication, and more into your services.

Error Handling: Built-in support exists for handling errors at the HTTP layer, distinguishing between handled and unhandled errors.

WebSockets: Built-in support for WebSockets allows for the creation of real-time applications using ZIO HTTP.

Testkit: ZIO HTTP provides first-class testing utilities that facilitate test writing without requiring a live server instance.

Interoperability: Interoperability with existing Scala/Java libraries is provided, enabling seamless integration with functionality from the Scala/Java ecosystem through the importation of blocking and non-blocking operations.

JSON and Binary Codecs: Built-in support for ZIO Schema enables encoding and decoding of request/response bodies, supporting various data types including JSON, Protobuf, Avro, and Thrift.

Template System: A built-in DSL facilitates writing HTML templates using Scala code.

OpenAPI Support: Built-in support is available for generating OpenAPI documentation for HTTP applications, and conversely, for generating HTTP endpoints from OpenAPI documentation.

ZIO HTTP CLI: Command-line applications can be built to interact with HTTP APIs by leveraging the power of ZIO CLI and ZIO HTTP.

Installation

Setup via build.sbt:

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

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. Let's see how it is simple to build a greeting server and call it using the client API.

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 Docs!

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

zio-http's People

Contributors

tusharmath avatar scala-steward avatar d11-amitsingh avatar vigoo avatar 987nabil avatar shrutiverma97 avatar devsprint avatar amitksingh1490 avatar khajavi avatar girdharshubham avatar adamgfraser avatar kyri-petrou avatar dinojohn avatar gciuloaica avatar jdegoes avatar tomtriple avatar renovate[bot] avatar scottweaver avatar swoogles avatar afsalthaj avatar wosin avatar dependabot[bot] avatar d11kaushik avatar runtologist avatar frekw avatar rajcspsg avatar smehta91d11 avatar ex0ns avatar wpoosanguansit avatar guizmaii avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.