Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/zio-series/2.x' into rc3
Browse files Browse the repository at this point in the history
  • Loading branch information
amitksingh1490 committed Apr 1, 2022
2 parents 909d89c + f3c0db5 commit bfd261f
Show file tree
Hide file tree
Showing 33 changed files with 717 additions and 471 deletions.
133 changes: 0 additions & 133 deletions docs/website/docs/getting-started.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/website/docs/v1.x/dsl/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ The below snippet tests an app that takes `Int` as input and responds by adding
object Spec extends DefaultRunnableSpec {

def spec = suite("http")(
test("1 + 1 = 2") {
testM("1 + 1 = 2") {
val app: Http[Any, Nothing, Int, Int] = Http.fromFunction[Int](_ + 1)
assertM(app(1))(equalTo(2))
}
Expand Down
4 changes: 2 additions & 2 deletions docs/website/docs/v1.x/dsl/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This section describes, ZIO HTTP Server and different configurations you can pro
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = {
server.make
.use(start =>
Console.printLine(s"Server started on port ${start.port}")
console.putStrLn(s"Server started on port ${start.port}")
*> ZIO.never,
).provideCustomLayer(ServerChannelFactory.auto ++ EventLoopGroup.auto(2))
.exitCode
Expand Down Expand Up @@ -84,7 +84,7 @@ object HelloWorldAdvanced extends App {
server.make
.use(_ =>
// Waiting for the server to start
Console.printLine(s"Server started on port $PORT")
console.putStrLn(s"Server started on port $PORT")

// Ensures the server doesn't die after printing
*> ZIO.never,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object HelloWorldAdvanced extends App {
server.make
.use(start =>
// Waiting for the server to start
Console.printLine(s"Server started on port ${start.port}")
console.putStrLn(s"Server started on port ${start.port}")

// Ensures the server doesn't die after printing
*> ZIO.never,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object HttpsClient extends App {
val program = for {
res <- Client.request(url, headers, sslOption)
data <- res.bodyAsString
_ <- Console.printLine { data }
_ <- console.putStrLn { data }
} yield ()

override def run(args: List[String]): URIO[zio.ZEnv, ExitCode]
Expand Down
2 changes: 1 addition & 1 deletion docs/website/docs/v1.x/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ import zhttp.http._
object Spec extends DefaultRunnableSpec {

def spec = suite("http")(
test("should be ok") {
testM("should be ok") {
val app = Http.ok
val req = Request()
assertM(app(req))(equalTo(Response.ok))
Expand Down
33 changes: 33 additions & 0 deletions docs/website/docs/v1.x/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,36 @@ sbt new dream11/zio-http.g8
* [scalafix-organize-imports](https://github.com/liancheng/scalafix-organize-imports)
* [sbt-revolver](https://github.com/spray/sbt-revolver)

## Efficient development process

The dependencies in the Dream11 g8 template were added to enable an efficient development process.

### sbt-revolver "hot-reload" changes

Sbt-revolver can watch application resources for change and automatically re-compile and then re-start the application under development. This provides a fast development-turnaround, the closest you can get to real hot-reloading.

Start your application from _sbt_ with the following command

```shell
~reStart
```

Pressing enter will stop watching for changes, but not stop the application. Use the following command to stop the application (shutdown hooks will not be executed).

```
reStop
```

In case you already have an _sbt_ server running, i.e. to provide your IDE with BSP information, use _sbtn_ instead of _sbt_ to run `~reStart`, this let's both _sbt_ sessions share one server.

### scalafmt automatically format source code

scalafmt will automatically format all source code and assert that all team members use consistent formatting.

### scalafix refactoring and linting

scalafix will mainly be used as a linting tool during everyday development, for example by removing unused dependencies or reporting errors for disabled features. Additionally it can simplify upgrades of Scala versions and dependencies, by executing predefined migration paths.

### sbt-native-packager

sbt-native-packager can package the application in the most popular formats, for example Docker images, rpm packages or graalVM native images.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package example

import io.netty.util.AsciiString
import zhttp.http._
import zhttp.http.{Http, _}
import zhttp.service.server.ServerChannelFactory
import zhttp.service.{EventLoopGroup, Server}
import zio._
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object Dependencies {
val JwtCoreVersion = "9.0.4"
val NettyVersion = "4.1.75.Final"
val NettyIncubatorVersion = "0.0.13.Final"
val ScalaCompactCollectionVersion = "2.6.0"
val ScalaCompactCollectionVersion = "2.7.0"
val ZioVersion = "2.0.0-RC3"
val SttpVersion = "3.3.18"

Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.2")
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")
addSbtPlugin("com.codecommit" % "sbt-github-actions" % "0.14.2")
addSbtPlugin("ch.epfl.scala" % "sbt-scala3-migrate" % "0.5.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scala3-migrate" % "0.5.1")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10")
14 changes: 7 additions & 7 deletions zio-http/src/main/scala/zhttp/html/Dom.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package zhttp.html
* elements.
*/
sealed trait Dom { self =>
def encode: String = self match {
def encode: CharSequence = self match {
case Dom.Element(name, children) =>
val attributes = children.collect { case self: Dom.Attribute => self.encode }

Expand All @@ -35,19 +35,19 @@ sealed trait Dom { self =>
}

object Dom {
def attr(name: String, value: String): Dom = Dom.Attribute(name, value)
def attr(name: CharSequence, value: CharSequence): Dom = Dom.Attribute(name, value)

def element(name: String, children: Dom*): Dom = Dom.Element(name, children)
def element(name: CharSequence, children: Dom*): Dom = Dom.Element(name, children)

def empty: Dom = Empty

def text(data: String): Dom = Dom.Text(data)
def text(data: CharSequence): Dom = Dom.Text(data)

private[zhttp] final case class Element(name: String, children: Seq[Dom]) extends Dom
private[zhttp] final case class Element(name: CharSequence, children: Seq[Dom]) extends Dom

private[zhttp] final case class Text(data: String) extends Dom
private[zhttp] final case class Text(data: CharSequence) extends Dom

private[zhttp] final case class Attribute(name: String, value: String) extends Dom
private[zhttp] final case class Attribute(name: CharSequence, value: CharSequence) extends Dom

private[zhttp] object Empty extends Dom
}
6 changes: 3 additions & 3 deletions zio-http/src/main/scala/zhttp/html/Elements.scala
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,12 @@ trait Elements {
}

object Element {
private[zhttp] val voidElementNames: Set[String] =
private[zhttp] val voidElementNames: Set[CharSequence] =
Set(area, base, br, col, embed, hr, img, input, link, meta, param, source, track, wbr).map(_.name)

private[zhttp] def isVoid(name: String): Boolean = voidElementNames.contains(name)
private[zhttp] def isVoid(name: CharSequence): Boolean = voidElementNames.contains(name)

case class PartialElement(name: String) {
case class PartialElement(name: CharSequence) {
def apply(children: Html*): Dom = Dom.element(
name,
children.collect {
Expand Down
4 changes: 2 additions & 2 deletions zio-http/src/main/scala/zhttp/html/Html.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scala.language.implicitConversions
* A view is a domain that used generate HTML.
*/
sealed trait Html { self =>
def encode: String = {
def encode: CharSequence = {
self match {
case Html.Empty => ""
case Html.Single(element) => element.encode
Expand All @@ -16,7 +16,7 @@ sealed trait Html { self =>
}

object Html {
implicit def fromString(string: String): Html = Html.Single(Dom.text(string))
implicit def fromString(string: CharSequence): Html = Html.Single(Dom.text(string))

implicit def fromSeq(elements: Seq[Dom]): Html = Html.Multiple(elements)

Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zhttp/html/Template.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package zhttp.html
*/
object Template {

def container(heading: String)(element: Html): Html = {
def container(heading: CharSequence)(element: Html): Html = {
html(
head(
title(s"ZIO Http - ${heading}"),
Expand Down
Loading

2 comments on commit bfd261f

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance Benchmark:

Concurrency: 256
Requests/sec: 972106.66

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance Benchmark:

Concurrency: 256
Requests/sec: 972438.13

Please sign in to comment.