SlideShare a Scribd company logo
Exploring ZIO HTTP
Presenter Name: Niloy Choudhury
Lack of etiquette and manners is a huge turn off.
KnolX Etiquettes
 Punctuality
Join the session 5 minutes prior to the session start time. We start on
time and conclude on time!
 Feedback
Make sure to submit a constructive feedback for all sessions as it is very
helpful for the presenter.
 Silent Mode
Keep your mobile devices in silent mode, feel free to move out of session
in case you need to attend an urgent call.
 Avoid Disturbance
Avoid unwanted chit chat during the session.
1. What is ZIO HTTP
 Http servers in general
 Mechanisms offered by ZIO HTTP
 How to write ZIO HTTP server (syntax)
2. ZIO HTTP Routing
3. Handlers, Query Params and URL Path
4. Request Response Interception (Middleware)
5. Error Handling
6. Server configuration
• A powerful library for building robust and scalable HTTP
servers.
• ZIO Http offers a functional and type-safe approach to server
development.
• Promotes code that's easy to understand, maintain, and test.
Http servers in general
 Routing
o Http Methods
o Path Variable
o Query Param
o Parse Request
 Request Response Interception
o Logging
o Middleware
 Error Handling
 Server Configuration
• A powerful routing mechanism for defining how incoming
requests map to specific handlers.
• Routes are built using a DSL.
• Plain data, description of route.
• Not pattern matching or partial function.
Routes
 Routes
o Models a collection of Route s
final case class Routes[-Env, +Err](routes: Chunk[zio.http.Route[Env,
Err]])
 A Route consists of two parts: RoutePattern and Handler
Method.GET / "hello" -> Handler.text("hello")
sealed trait Route[-Env, +Err]
o RoutePattern define how URLs map to handlers.
o Patterns can include literal strings, wildcards for any path segment, and path parameters.
o The Handler produces response to the matching request.
Handler
 A Handler is responsible for processing the matched incoming HTTP requests and generating
appropriate response.
sealed trait Handler[-R, +Err, -In, +Out]
type RequestHandler[-R, +Err] = Handler[R, Err, Request, Response]
o Function that takes a Request, including headers, body, and parameters.
o Generates a Response object.
o Response including status code, headers, and an optional body.
 Creating Handler
o Using companion object
Method.GET / "hello" -> Handler.text("hello !")
Method.GET / "forbidden" -> Handler.error(Status.Forbidden)
o Using smart constructor handler
Method.GET / Root -> handler(Response.text("Greetings at your service"))
Request
 ZIO HTTP Request represents a Http
request object
 Accessing incoming Request
o Method.POST / "echo" -> handler { req:
Request =>
req.body.asString.map(Response.text(_))
}.sandbox
 Query Params (Not part of the route)
o Method.GET / "search" -> handler { (req:
Request) =>
val queries: Option[String] =
req.queryParam("q")
...
 final case class Request(
version: Version = Version.Default,
method: Method = Method.ANY,
url: URL = URL.empty,
headers: Headers = Headers.empty,
body: Body = Body.empty,
remoteAddress: Option[InetAddress] =
None,
remoteCertificate: Option[Certificate] =
None,
) extends HeaderOps[Request]
Request object
Request Response Interception (Middleware)
 Intercept HTTP requests and responses before they reach the handler.
 Implement cross-cutting concerns like logging, validation.
 Accepts a Routes and produces a new Routes.
 Middleware can be chained together to form a processing pipeline for requests and responses.
 trait Middleware[-UpperEnv] { self =>
def apply[Env1 <: UpperEnv, Err](app: Routes[Env1, Err]): Routes[Env1, Err]
...
 private val logWithUserAgent: Middleware[Any] =
Middleware.logAnnotateHeaders(Header.UserAgent)
 routes @@ requestLogging @@ logWithUserAgent
Server Configuration
 ZIO HTTP server provides methods to install HTTP applications into the server.
 Offers a comprehensive Config class for control over server behavior, helps to configure
o SSL/TLS
o address binding
o request decompression
o response compression
 Serve routes using the Server.serve method
o Server.serve(routes).provide(Server.default)
 Customizing config
o Server.serve(ZIORoutes.routes)
.provide(ZLayer.succeed(Server.Config.default.port(8081)),
Server.live
)
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development

More Related Content

ODP
An Introduction to Akka http
Knoldus Inc.
 
PDF
Practical Akka HTTP - introduction
Łukasz Sowa
 
PDF
Liberated APIs in ClojureLand - Paris Clojure User Group
Gaylord Mazelier
 
PDF
Spray human talks
antoinecomte
 
PPTX
From ZERO to REST in an hour
Cisco DevNet
 
PDF
scalaphx-akka-http
Terry Drozdowski
 
PPTX
Web technology Unit-I Part D - message format
SSN College of Engineering, Kalavakkam
 
ODP
Akka http
Knoldus Inc.
 
An Introduction to Akka http
Knoldus Inc.
 
Practical Akka HTTP - introduction
Łukasz Sowa
 
Liberated APIs in ClojureLand - Paris Clojure User Group
Gaylord Mazelier
 
Spray human talks
antoinecomte
 
From ZERO to REST in an hour
Cisco DevNet
 
scalaphx-akka-http
Terry Drozdowski
 
Web technology Unit-I Part D - message format
SSN College of Engineering, Kalavakkam
 
Akka http
Knoldus Inc.
 

Similar to ZIO Http A Functional Approach to Scalable and Type-Safe Web Development (20)

PDF
Building REST API using Akka HTTP with Scala
Knoldus Inc.
 
PDF
HTTPBuilder NG: Back From The Dead
noamt
 
PDF
The never-ending REST API design debate
Restlet
 
PPTX
Performance #4 network
Vitali Pekelis
 
PDF
Rest with-spray
Nimrod Argov
 
PDF
Advanced I/O in browser
Eugene Lazutkin
 
PPTX
Api 101
DrSimoneDiCola
 
PDF
Facebook & Twitter API
Fabrice Delhoste
 
PPTX
Web Application Technologies
Se-Han Lee
 
PDF
Android Performance #4: Network
Yonatan Levin
 
PDF
HTTP In-depth
Vinayak Hegde
 
PDF
The Art of API Design - PHP Tek 2025, Chris Tankersley
Chris Tankersley
 
PPTX
Http Introduction
Akshay Dhole
 
PPTX
Dev traning 2016 intro to the web
Sacheen Dhanjie
 
PDF
The never-ending REST API design debate -- Devoxx France 2016
Restlet
 
PDF
DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
Aman Kohli
 
PDF
HTTP Request and Response Structure
BhagyashreeGajera1
 
PDF
Great webapis
Rafał Hryniewski
 
ZIP
spray: REST on Akka
sirthias
 
PDF
Customising Your Own Web Framework In Go
Jonathan Gomez
 
Building REST API using Akka HTTP with Scala
Knoldus Inc.
 
HTTPBuilder NG: Back From The Dead
noamt
 
The never-ending REST API design debate
Restlet
 
Performance #4 network
Vitali Pekelis
 
Rest with-spray
Nimrod Argov
 
Advanced I/O in browser
Eugene Lazutkin
 
Facebook & Twitter API
Fabrice Delhoste
 
Web Application Technologies
Se-Han Lee
 
Android Performance #4: Network
Yonatan Levin
 
HTTP In-depth
Vinayak Hegde
 
The Art of API Design - PHP Tek 2025, Chris Tankersley
Chris Tankersley
 
Http Introduction
Akshay Dhole
 
Dev traning 2016 intro to the web
Sacheen Dhanjie
 
The never-ending REST API design debate -- Devoxx France 2016
Restlet
 
DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
Aman Kohli
 
HTTP Request and Response Structure
BhagyashreeGajera1
 
Great webapis
Rafał Hryniewski
 
spray: REST on Akka
sirthias
 
Customising Your Own Web Framework In Go
Jonathan Gomez
 
Ad

More from Knoldus Inc. (20)

PPTX
Angular Hydration Presentation (FrontEnd)
Knoldus Inc.
 
PPTX
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Knoldus Inc.
 
PPTX
Self-Healing Test Automation Framework - Healenium
Knoldus Inc.
 
PPTX
Kanban Metrics Presentation (Project Management)
Knoldus Inc.
 
PPTX
Java 17 features and implementation.pptx
Knoldus Inc.
 
PPTX
Chaos Mesh Introducing Chaos in Kubernetes
Knoldus Inc.
 
PPTX
GraalVM - A Step Ahead of JVM Presentation
Knoldus Inc.
 
PPTX
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
PPTX
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
PPTX
DAPR - Distributed Application Runtime Presentation
Knoldus Inc.
 
PPTX
Introduction to Azure Virtual WAN Presentation
Knoldus Inc.
 
PPTX
Introduction to Argo Rollouts Presentation
Knoldus Inc.
 
PPTX
Intro to Azure Container App Presentation
Knoldus Inc.
 
PPTX
Insights Unveiled Test Reporting and Observability Excellence
Knoldus Inc.
 
PPTX
Introduction to Splunk Presentation (DevOps)
Knoldus Inc.
 
PPTX
Code Camp - Data Profiling and Quality Analysis Framework
Knoldus Inc.
 
PPTX
AWS: Messaging Services in AWS Presentation
Knoldus Inc.
 
PPTX
Amazon Cognito: A Primer on Authentication and Authorization
Knoldus Inc.
 
PPTX
Managing State & HTTP Requests In Ionic.
Knoldus Inc.
 
PPTX
Facilitation Skills - When to Use and Why.pptx
Knoldus Inc.
 
Angular Hydration Presentation (FrontEnd)
Knoldus Inc.
 
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Knoldus Inc.
 
Self-Healing Test Automation Framework - Healenium
Knoldus Inc.
 
Kanban Metrics Presentation (Project Management)
Knoldus Inc.
 
Java 17 features and implementation.pptx
Knoldus Inc.
 
Chaos Mesh Introducing Chaos in Kubernetes
Knoldus Inc.
 
GraalVM - A Step Ahead of JVM Presentation
Knoldus Inc.
 
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
DAPR - Distributed Application Runtime Presentation
Knoldus Inc.
 
Introduction to Azure Virtual WAN Presentation
Knoldus Inc.
 
Introduction to Argo Rollouts Presentation
Knoldus Inc.
 
Intro to Azure Container App Presentation
Knoldus Inc.
 
Insights Unveiled Test Reporting and Observability Excellence
Knoldus Inc.
 
Introduction to Splunk Presentation (DevOps)
Knoldus Inc.
 
Code Camp - Data Profiling and Quality Analysis Framework
Knoldus Inc.
 
AWS: Messaging Services in AWS Presentation
Knoldus Inc.
 
Amazon Cognito: A Primer on Authentication and Authorization
Knoldus Inc.
 
Managing State & HTTP Requests In Ionic.
Knoldus Inc.
 
Facilitation Skills - When to Use and Why.pptx
Knoldus Inc.
 
Ad

Recently uploaded (20)

PDF
Software Development Company | KodekX
KodekX
 
PDF
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
AbdullahSani29
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PPTX
The Power of IoT Sensor Integration in Smart Infrastructure and Automation.pptx
Rejig Digital
 
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
CIFDAQ
 
PPTX
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PDF
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
famaw19526
 
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
AVTRON Technologies LLC
 
PPTX
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Software Development Company | KodekX
KodekX
 
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
AbdullahSani29
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
The Power of IoT Sensor Integration in Smart Infrastructure and Automation.pptx
Rejig Digital
 
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
CIFDAQ
 
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
famaw19526
 
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
AVTRON Technologies LLC
 
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 

ZIO Http A Functional Approach to Scalable and Type-Safe Web Development

  • 1. Exploring ZIO HTTP Presenter Name: Niloy Choudhury
  • 2. Lack of etiquette and manners is a huge turn off. KnolX Etiquettes  Punctuality Join the session 5 minutes prior to the session start time. We start on time and conclude on time!  Feedback Make sure to submit a constructive feedback for all sessions as it is very helpful for the presenter.  Silent Mode Keep your mobile devices in silent mode, feel free to move out of session in case you need to attend an urgent call.  Avoid Disturbance Avoid unwanted chit chat during the session.
  • 3. 1. What is ZIO HTTP  Http servers in general  Mechanisms offered by ZIO HTTP  How to write ZIO HTTP server (syntax) 2. ZIO HTTP Routing 3. Handlers, Query Params and URL Path 4. Request Response Interception (Middleware) 5. Error Handling 6. Server configuration
  • 4. • A powerful library for building robust and scalable HTTP servers. • ZIO Http offers a functional and type-safe approach to server development. • Promotes code that's easy to understand, maintain, and test.
  • 5. Http servers in general  Routing o Http Methods o Path Variable o Query Param o Parse Request  Request Response Interception o Logging o Middleware  Error Handling  Server Configuration
  • 6. • A powerful routing mechanism for defining how incoming requests map to specific handlers. • Routes are built using a DSL. • Plain data, description of route. • Not pattern matching or partial function.
  • 7. Routes  Routes o Models a collection of Route s final case class Routes[-Env, +Err](routes: Chunk[zio.http.Route[Env, Err]])  A Route consists of two parts: RoutePattern and Handler Method.GET / "hello" -> Handler.text("hello") sealed trait Route[-Env, +Err] o RoutePattern define how URLs map to handlers. o Patterns can include literal strings, wildcards for any path segment, and path parameters. o The Handler produces response to the matching request.
  • 8. Handler  A Handler is responsible for processing the matched incoming HTTP requests and generating appropriate response. sealed trait Handler[-R, +Err, -In, +Out] type RequestHandler[-R, +Err] = Handler[R, Err, Request, Response] o Function that takes a Request, including headers, body, and parameters. o Generates a Response object. o Response including status code, headers, and an optional body.  Creating Handler o Using companion object Method.GET / "hello" -> Handler.text("hello !") Method.GET / "forbidden" -> Handler.error(Status.Forbidden) o Using smart constructor handler Method.GET / Root -> handler(Response.text("Greetings at your service"))
  • 9. Request  ZIO HTTP Request represents a Http request object  Accessing incoming Request o Method.POST / "echo" -> handler { req: Request => req.body.asString.map(Response.text(_)) }.sandbox  Query Params (Not part of the route) o Method.GET / "search" -> handler { (req: Request) => val queries: Option[String] = req.queryParam("q") ...  final case class Request( version: Version = Version.Default, method: Method = Method.ANY, url: URL = URL.empty, headers: Headers = Headers.empty, body: Body = Body.empty, remoteAddress: Option[InetAddress] = None, remoteCertificate: Option[Certificate] = None, ) extends HeaderOps[Request] Request object
  • 10. Request Response Interception (Middleware)  Intercept HTTP requests and responses before they reach the handler.  Implement cross-cutting concerns like logging, validation.  Accepts a Routes and produces a new Routes.  Middleware can be chained together to form a processing pipeline for requests and responses.  trait Middleware[-UpperEnv] { self => def apply[Env1 <: UpperEnv, Err](app: Routes[Env1, Err]): Routes[Env1, Err] ...  private val logWithUserAgent: Middleware[Any] = Middleware.logAnnotateHeaders(Header.UserAgent)  routes @@ requestLogging @@ logWithUserAgent
  • 11. Server Configuration  ZIO HTTP server provides methods to install HTTP applications into the server.  Offers a comprehensive Config class for control over server behavior, helps to configure o SSL/TLS o address binding o request decompression o response compression  Serve routes using the Server.serve method o Server.serve(routes).provide(Server.default)  Customizing config o Server.serve(ZIORoutes.routes) .provide(ZLayer.succeed(Server.Config.default.port(8081)), Server.live )