Skip to content

Commit

Permalink
Refactor: Change root package to zio.http from zhttp (zio#1430)
Browse files Browse the repository at this point in the history
* refactor: change internal structure

* chore: rename `dream11` to `zio`

* style: scalafmt

* refactor: move to ZIO package

* refactor: move rename examples dir

* refactor: move `html` to `zio.http`

* refactor: move `socket` to `zio.http`

* refactor: move `service` into `zio.http`

* chore: update workflow

* refactor: fix for scala 2.12

* chore: update benchmark server

* chore: update file

* doc: update docs

* doc: update readme

* refactor: move more files

* chore: fix compiler error

* refactor: move server and client into root package

* doc: update docs

* style: scalafmt

* style: scalafmt
  • Loading branch information
tusharmath authored Sep 11, 2022
1 parent 8abe68b commit e51ded1
Show file tree
Hide file tree
Showing 204 changed files with 735 additions and 1,348 deletions.
583 changes: 4 additions & 579 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Check out the full documentation here: [Documentation]

[Documentation]: https://zio.github.io/zio-http

![Continuous Integration](https://github.com/dream11/zio-http/workflows/Continuous%20Integration/badge.svg)
![Continuous Integration](https://github.com/zio/zio-http/workflows/Continuous%20Integration/badge.svg)
[![Discord Chat](https://img.shields.io/discord/629491597070827530.svg?logo=discord)](https://discord.com/channels/629491597070827530/819703129267372113)
[![Sonatype Nexus (Releases)](https://img.shields.io/nexus/r/io.d11/zhttp_2.13?server=https%3A%2F%2Fs01.oss.sonatype.org)](https://oss.sonatype.org/content/repositories/releases/io/d11/zhttp_2.13/)
[![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/io.d11/zhttp_2.13?server=https%3A%2F%2Fs01.oss.sonatype.org)](https://s01.oss.sonatype.org/content/repositories/snapshots/io/d11/zhttp_2.13/)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/dream11/zio-http.svg)](http://isitmaintained.com/project/dream11/zio-http "Average time to resolve an issue")
[![Open in Visual Studio Code](https://open.vscode.dev/badges/open-in-vscode.svg)](https://open.vscode.dev/dream11/zio-http)
[![Sonatype Nexus (Releases)](https://img.shields.io/nexus/r/dev.zio/zio-http_2.13?server=https%3A%2F%2Fs01.oss.sonatype.org)](https://oss.sonatype.org/content/repositories/releases/dev/zio/zio-http_2.13/)
[![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/dev.zio/zio-http_2.13?server=https%3A%2F%2Fs01.oss.sonatype.org)](https://s01.oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-http_2.13/)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/zio/zio-http.svg)](http://isitmaintained.com/project/zio/zio-http "Average time to resolve an issue")
[![Open in Visual Studio Code](https://open.vscode.dev/badges/open-in-vscode.svg)](https://open.vscode.dev/zio/zio-http)

[zio]: https://zio.dev
[netty]: http://netty.io
Expand All @@ -28,8 +28,8 @@ Check out the full documentation here: [Documentation]
A simple Http server can be built using a few lines of code.

```scala
import zhttp.http._
import zhttp.service.Server
import zio.http._
import zio.http.Server
import zio._

object HelloWorld extends ZIOAppDefault {
Expand All @@ -44,21 +44,21 @@ object HelloWorld extends ZIOAppDefault {
```
#### Examples

You can checkout more examples in the [example](https://github.com/dream11/zio-http/tree/main/example/src/main/scala/example) project —
You can checkout more examples in the [example](https://github.com/zio/zio-http/tree/main/example/src/main/scala/example) project —

- [Simple Server](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/example/HelloWorld.scala)
- [Advanced Server](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/example/HelloWorldAdvanced.scala)
- [WebSocket Server](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/example/WebSocketEcho.scala)
- [Streaming Response](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/example/StreamingResponse.scala)
- [Simple Client](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/example/SimpleClient.scala)
- [File Streaming](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/example/FileStreaming.scala)
- [Basic Authentication](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/example/BasicAuth.scala)
- [JWT Authentication Client](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/example/AuthenticationClient.scala)
- [JWT Authentication Server](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/example/AuthenticationServer.scala)
- [Simple Server](https://github.com/zio/zio-http/blob/main/example/src/main/scala/example/HelloWorld.scala)
- [Advanced Server](https://github.com/zio/zio-http/blob/main/example/src/main/scala/example/HelloWorldAdvanced.scala)
- [WebSocket Server](https://github.com/zio/zio-http/blob/main/example/src/main/scala/example/WebSocketEcho.scala)
- [Streaming Response](https://github.com/zio/zio-http/blob/main/example/src/main/scala/example/StreamingResponse.scala)
- [Simple Client](https://github.com/zio/zio-http/blob/main/example/src/main/scala/example/SimpleClient.scala)
- [File Streaming](https://github.com/zio/zio-http/blob/main/example/src/main/scala/example/FileStreaming.scala)
- [Basic Authentication](https://github.com/zio/zio-http/blob/main/example/src/main/scala/example/BasicAuth.scala)
- [JWT Authentication Client](https://github.com/zio/zio-http/blob/main/example/src/main/scala/example/AuthenticationClient.scala)
- [JWT Authentication Server](https://github.com/zio/zio-http/blob/main/example/src/main/scala/example/AuthenticationServer.scala)

#### Steps to run an example

1. Edit the [RunSettings](https://github.com/dream11/zio-http/blob/main/project/BuildHelper.scala#L109) - modify `className` to the example you'd like to run.
1. Edit the [RunSettings](https://github.com/zio/zio-http/blob/main/project/BuildHelper.scala#L109) - modify `className` to the example you'd like to run.
2. From sbt shell, run `~example/reStart`. You should see `Server started on port: 8090`.
3. Send curl request for defined `http Routes`, for eg : `curl -i "http://localhost:8090/text"` for `example.HelloWorld`.

Expand All @@ -67,7 +67,7 @@ You can checkout more examples in the [example](https://github.com/dream11/zio-h
Setup via `build.sbt`

```scala
libraryDependencies += "io.d11" %% "zhttp" % "[version]"
libraryDependencies += "dev.zio" %% "zio-http" % "[version]"
```

**NOTE:** ZIO Http is compatible with `ZIO 1.x` and `ZIO 2.x`.
Expand Down
34 changes: 17 additions & 17 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import sbt.librarymanagement.ScalaArtifacts.isScala3
val releaseDrafterVersion = "5"

// Setting default log level to INFO
val _ = sys.props += ("ZHttpLogLevel" -> Debug.ZHttpLogLevel)
val _ = sys.props += ("ZIOHttpLogLevel" -> Debug.ZIOHttpLogLevel)

// CI Configuration
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.graalvm("21.1.0", "11"), JavaSpec.temurin("8"))
Expand Down Expand Up @@ -87,14 +87,14 @@ lazy val root = (project in file("."))
.settings(stdSettings("root"))
.settings(publishSetting(false))
.aggregate(
zhttp,
zhttpBenchmarks,
zhttpLogging,
example,
zioHttp,
zioHttpBenchmarks,
zioHttpLogging,
zioHttpExample,
)

lazy val zhttp = (project in file("zio-http"))
.settings(stdSettings("zhttp"))
lazy val zioHttp = (project in file("zio-http"))
.settings(stdSettings("zio-http"))
.settings(publishSetting(true))
.settings(meta)
.settings(
Expand All @@ -113,18 +113,18 @@ lazy val zhttp = (project in file("zio-http"))
}
},
)
.dependsOn(zhttpLogging)
.dependsOn(zioHttpLogging)

lazy val zhttpBenchmarks = (project in file("zio-http-benchmarks"))
lazy val zioHttpBenchmarks = (project in file("zio-http-benchmarks"))
.enablePlugins(JmhPlugin)
.dependsOn(zhttp)
.settings(stdSettings("zhttpBenchmarks"))
.dependsOn(zioHttp)
.settings(stdSettings("zio-http-benchmarks"))
.settings(publishSetting(false))
.settings(libraryDependencies ++= Seq(zio))

lazy val zhttpLogging = (project in file("zio-http-logging"))
.settings(stdSettings("zhttp-logging"))
.settings(publishSetting(true))
lazy val zioHttpLogging = (project in file("zio-http-logging"))
.settings(stdSettings("zio-http-logging"))
.settings(publishSetting(false))
.settings(
libraryDependencies ++= {
if (isScala3(scalaVersion.value)) Seq.empty
Expand All @@ -136,9 +136,9 @@ lazy val zhttpLogging = (project in file("zio-http-logging"))
libraryDependencies ++= Seq(`zio-test`, `zio-test-sbt`),
)

lazy val example = (project in file("./example"))
.settings(stdSettings("example"))
lazy val zioHttpExample = (project in file("zio-http-example"))
.settings(stdSettings("zio-http-example"))
.settings(publishSetting(false))
.settings(runSettings(Debug.Main))
.settings(libraryDependencies ++= Seq(`jwt-core`))
.dependsOn(zhttp)
.dependsOn(zioHttp)
32 changes: 16 additions & 16 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
## Creating a "_Hello World_" app

```scala
import zhttp.http._
import zio.http._

val app = Http.text("Hello World!")
```

An application can be made using any of the available operators on `zhttp.Http`. In the above program for any Http request, the response is always `"Hello World!"`.
An application can be made using any of the available operators on `zio.Http`. In the above program for any Http request, the response is always `"Hello World!"`.

## Routing

```scala
import zhttp.http._
import zio.http._

val app = Http.collect[Request] {
case Method.GET -> Root / "fruits" / "a" => Response.text("Apple")
Expand All @@ -41,7 +41,7 @@ Pattern matching on route is supported by the framework
## Composition

```scala
import zhttp.http._
import zio.http._

val a = Http.collect[Request] { case Method.GET -> Root / "a" => Response.ok }
val b = Http.collect[Request] { case Method.GET -> Root / "b" => Response.ok }
Expand All @@ -64,7 +64,7 @@ val app = Http.collectM[Request] {
## Accessing the Request

```scala
import zhttp.http._
import zio.http._

val app = Http.collect[Request] {
case req @ Method.GET -> Root / "fruits" / "a" =>
Expand All @@ -81,7 +81,7 @@ Tests suites could be implemented using `zio-test` library, as following:
```scala

import zio.test._
import zhttp.http._
import zio.http._
import zio.test.Assertion.equalTo

object Spec extends DefaultRunnableSpec {
Expand All @@ -104,7 +104,7 @@ object Spec extends DefaultRunnableSpec {
## Creating a socket app

```scala
import zhttp.socket._
import zio.socket._

private val socket = Socket.collect[WebSocketFrame] {
case WebSocketFrame.Text("FOO") => ZStream.succeed(WebSocketFrame.text("BAR"))
Expand All @@ -121,8 +121,8 @@ private val app = Http.collect[Request] {
## Starting an Http App

```scala
import zhttp.http._
import zhttp.service.Server
import zio.http._
import zio.http.Server
import zio._

object HelloWorld extends App {
Expand All @@ -137,10 +137,10 @@ A simple Http app that responds with empty content and a `200` status code is de

# Examples

- [Simple Server](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/HelloWorld.scala)
- [Advanced Server](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/HelloWorldAdvanced.scala)
- [WebSocket Server](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/SocketEchoServer.scala)
- [Streaming Response](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/StreamingResponse.scala)
- [Simple Client](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/SimpleClient.scala)
- [File Streaming](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/FileStreaming.scala)
- [Authentication](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/Authentication.scala)
- [Simple Server](https://github.com/zio/zio-http/blob/main/example/src/main/scala/HelloWorld.scala)
- [Advanced Server](https://github.com/zio/zio-http/blob/main/example/src/main/scala/HelloWorldAdvanced.scala)
- [WebSocket Server](https://github.com/zio/zio-http/blob/main/example/src/main/scala/SocketEchoServer.scala)
- [Streaming Response](https://github.com/zio/zio-http/blob/main/example/src/main/scala/StreamingResponse.scala)
- [Simple Client](https://github.com/zio/zio-http/blob/main/example/src/main/scala/SimpleClient.scala)
- [File Streaming](https://github.com/zio/zio-http/blob/main/example/src/main/scala/FileStreaming.scala)
- [Authentication](https://github.com/zio/zio-http/blob/main/example/src/main/scala/Authentication.scala)
24 changes: 12 additions & 12 deletions docs/website/docs/v1.x/dsl/headers.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ On the Server-side you can read Request headers as given below
- Example below shows how the Headers could be added to a response by using `Response` constructors and how a custom header is added to `Response` through `addHeader`:

```scala
import zhttp.http._
import zhttp.service.Server
import zio.http._
import zio.http.Server
import zio.{App, Chunk, ExitCode, URIO}
import zio.stream.ZStream

Expand Down Expand Up @@ -103,8 +103,8 @@ On the Server-side you can read Request headers as given below
```

- More examples:
- [BasicAuth](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/BasicAuth.scala)
- [Authentication](https://github.com/dream11/zio-http/blob/main/example/src/main/scala/Authentication.scala)
- [BasicAuth](https://github.com/zio/zio-http/blob/main/example/src/main/scala/BasicAuth.scala)
- [Authentication](https://github.com/zio/zio-http/blob/main/example/src/main/scala/Authentication.scala)

</details>

Expand All @@ -131,8 +131,8 @@ val responseHeaders: Task[Headers] = Client.request(url).map(_.headers)
- The sample below shows how a header could be added to a client request:

```scala
import zhttp.http._
import zhttp.service._
import zio.http._
import zio.http.service._
import zio._

object SimpleClientJson extends App {
Expand Down Expand Up @@ -166,17 +166,17 @@ val responseHeaders: Task[Headers] = Client.request(url).map(_.headers)

Headers DSL provides plenty of powerful operators that can be used to add, remove, modify and verify headers. Headers APIs could be used on client, server, and middleware.

`zhttp.http.Headers` - represents an immutable collection of headers i.e. essentially a `Chunk[(String, String)]`.
`zio.http.Headers` - represents an immutable collection of headers i.e. essentially a `Chunk[(String, String)]`.

`zhttp.http.HeaderNames` - commonly used header names.
`zio.http.HeaderNames` - commonly used header names.

`zhttp.http.HeaderValues` - commonly used header values
`zio.http.HeaderValues` - commonly used header values

`Headers` have following type of helpers
- Constructors - Provides a list of helpful methods that can create `Headers`.

```scala
import zhttp.http._
import zio.http._

// create a simple Accept header:
val acceptHeader: Headers = Headers.accept(HeaderValues.applicationJson)
Expand All @@ -188,7 +188,7 @@ Headers DSL provides plenty of powerful operators that can be used to add, remov
- Getters - Provides a list of operators that parse and extract data from the `Headers`.

```scala
import zhttp.http._
import zio.http._

// retrieving the value of Accept header value:
val acceptHeader: Headers = Headers.accept(HeaderValues.applicationJson)
Expand All @@ -203,7 +203,7 @@ Headers DSL provides plenty of powerful operators that can be used to add, remov
- Modifiers - Provides a list of operators that modify the current `Headers`. Once modified, a new instance of the same type is returned.

```scala
import zhttp.http._
import zio.http._

// add Accept header:
val headers = Headers.empty
Expand Down
8 changes: 4 additions & 4 deletions docs/website/docs/v1.x/dsl/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ Since an HTTP application `Http[R, E, A, B]` is a function from `A` to `ZIO[R, O

The below snippet tests an app that takes `Int` as input and responds by adding 1 to the input.
```scala
package zhttp.http.middleware
package zio.http.middleware

import zhttp.http._
import zio.http._
import zio.test.Assertion.equalTo
import zio.test._

Expand Down Expand Up @@ -359,8 +359,8 @@ We can also convert an `Http` to `HttpApp` using codec middlewares that take in
ZIO HTTP server needs an `HttpApp[R,E]` for running.
We can use `Server.app()` method to bootstrap the server with an `HttpApp[R,E]`
```scala
import zhttp.http._
import zhttp.service.Server
import zio.http._
import zio.http.Server
import zio._

object HelloWorld extends App {
Expand Down
Loading

0 comments on commit e51ded1

Please sign in to comment.