---
id: http-client-server
title: HTTP Client-Server Example
sidebar_label: HTTP Client-Server
---

## Client and Server Example

```scala title="zio-http-example/src/main/scala/example/ClientServer.scala" 
package example

import zio.ZIOAppDefault

import zio.http._

object ClientServer extends ZIOAppDefault {
  val url = URL.decode("http://localhost:8080/hello").toOption.get

  val app = Routes(
    Method.GET / "hello" -> handler(Response.text("hello")),
    Method.GET / ""      -> handler(ZClient.batched(Request.get(url))),
  ).sandbox

  val run =
    Server.serve(app).provide(Server.default, Client.default).exitCode
}
```

## Simple Client Example

```scala title="zio-http-example/src/main/scala/example/SimpleClient.scala" 
package example

import zio._

import zio.http._

object SimpleClient extends ZIOAppDefault {
  val url = URL.decode("https://jsonplaceholder.typicode.com/todos").toOption.get

  val program = for {
    client <- ZIO.service[Client]
    res    <- client.url(url).batched(Request.get("/"))
    data   <- res.body.asString
    _      <- Console.printLine(data)
  } yield ()

  override val run = program.provide(Client.default)

}
```
