Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/zio/zio-http into docs-rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
varshith257 committed Jul 30, 2024
2 parents 10cfb3c + 12f0c26 commit 3477c32
Show file tree
Hide file tree
Showing 125 changed files with 14,575 additions and 9,143 deletions.
45 changes: 43 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
run: sbt '++ ${{ matrix.scala }}' zioHttpShadedTests/test

- name: Compress target directories
run: tar cf targets.tar sbt-zio-http-grpc/target zio-http-cli/target target zio-http/jvm/target zio-http-docs/target sbt-zio-http-grpc-tests/target zio-http-gen/target zio-http-benchmarks/target zio-http-example/target zio-http-testkit/target zio-http/js/target zio-http-htmx/target project/target
run: tar cf targets.tar sbt-zio-http-grpc/target zio-http-cli/target target zio-http/jvm/target zio-http-docs/target sbt-zio-http-grpc-tests/target zio-http-gen/target zio-http-benchmarks/target zio-http-tools/target zio-http-example/target zio-http-testkit/target zio-http/js/target zio-http-htmx/target project/target

- name: Upload target directories
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -285,6 +285,40 @@ jobs:
name: Jmh_Main_CachedDateHeaderBenchmark
path: Main_CachedDateHeaderBenchmark.txt

Jmh_ClientBenchmark:
name: Jmh ClientBenchmark
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.14]
java: [temurin@8]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
with:
path: zio-http

- uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 11

- name: Benchmark_Main
id: Benchmark_Main
env:
GITHUB_TOKEN: ${{secrets.ACTIONS_PAT}}
run: |
cd zio-http
sed -i -e '$aaddSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.7")' project/plugins.sbt
cat > Main_ClientBenchmark.txt
sbt -no-colors -v "zioHttpBenchmarks/jmh:run -i 3 -wi 3 -f1 -t1 ClientBenchmark" | grep -e "thrpt" -e "avgt" >> ../Main_ClientBenchmark.txt
- uses: actions/upload-artifact@v3
with:
name: Jmh_Main_ClientBenchmark
path: Main_ClientBenchmark.txt

Jmh_CookieDecodeBenchmark:
name: Jmh CookieDecodeBenchmark
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
Expand Down Expand Up @@ -627,7 +661,7 @@ jobs:

Jmh_cache:
name: Cache Jmh benchmarks
needs: [Jmh_CachedDateHeaderBenchmark, Jmh_CookieDecodeBenchmark, Jmh_EndpointBenchmark, Jmh_HttpCollectEval, Jmh_HttpCombineEval, Jmh_HttpNestedFlatMapEval, Jmh_HttpRouteTextPerf, Jmh_ProbeContentTypeBenchmark, Jmh_SchemeDecodeBenchmark, Jmh_ServerInboundHandlerBenchmark, Jmh_UtilBenchmark]
needs: [Jmh_CachedDateHeaderBenchmark, Jmh_ClientBenchmark, Jmh_CookieDecodeBenchmark, Jmh_EndpointBenchmark, Jmh_HttpCollectEval, Jmh_HttpCombineEval, Jmh_HttpNestedFlatMapEval, Jmh_HttpRouteTextPerf, Jmh_ProbeContentTypeBenchmark, Jmh_SchemeDecodeBenchmark, Jmh_ServerInboundHandlerBenchmark, Jmh_UtilBenchmark]
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
strategy:
matrix:
Expand All @@ -643,6 +677,13 @@ jobs:
- name: Format_Main_CachedDateHeaderBenchmark
run: cat Main_CachedDateHeaderBenchmark.txt >> Main_benchmarks.txt

- uses: actions/download-artifact@v3
with:
name: Jmh_Main_ClientBenchmark

- name: Format_Main_ClientBenchmark
run: cat Main_ClientBenchmark.txt >> Main_benchmarks.txt

- uses: actions/download-artifact@v3
with:
name: Jmh_Main_CookieDecodeBenchmark
Expand Down
50 changes: 37 additions & 13 deletions .github/workflows/site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,40 +57,64 @@ jobs:
run: sbt docs/publishToNpm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
generate-readme:
name: Generate README
update-readme:
name: Update README
runs-on: ubuntu-latest
if: ${{ (github.event_name == 'push') || ((github.event_name == 'release') && (github.event.action == 'published')) }}
continue-on-error: false
if: ${{ github.event_name == 'push' }}
steps:
- name: Git Checkout
uses: actions/checkout@v3.3.0
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: '0'
- name: Install libuv
run: sudo apt-get update && sudo apt-get install -y libuv1-dev
- name: Setup Scala
uses: actions/setup-java@v3.9.0
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
distribution: corretto
java-version: '17'
check-latest: true
- name: Cache Dependencies
uses: coursier/cache-action@v6
- name: Generate Readme
run: sbt docs/generateReadme
run: sbt docs/generateReadme
- name: Commit Changes
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git config --local user.email "zio-assistant[bot]@users.noreply.github.com"
git config --local user.name "ZIO Assistant"
git add README.md
git commit -m "Update README.md" || echo "No changes to commit"
- name: Generate Token
id: generate-token
uses: zio/[email protected]
with:
app_id: ${{ secrets.APP_ID }}
app_private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Create Pull Request
uses: peter-evans/[email protected]
id: cpr
uses: peter-evans/create-pull-request@v6
with:
body: |-
Autogenerated changes after running the `sbt docs/generateReadme` command of the [zio-sbt-website](https://zio.dev/zio-sbt) plugin.
I will automatically update the README.md file whenever there is new change for README.md, e.g.
I will automatically update the README.md file whenever there is a new change for README.md, e.g.
- After each release, I will update the version in the installation section.
- After any changes to the "docs/index.md" file, I will update the README.md file accordingly.
branch: zio-sbt-website/update-readme
commit-message: Update README.md
token: ${{ steps.generate-token.outputs.token }}
delete-branch: true
title: Update README.md
- name: Approve PR
if: ${{ steps.cpr.outputs.pull-request-number }}
run: gh pr review "$PR_URL" --approve
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_URL: ${{ steps.cpr.outputs.pull-request-url }}
- name: Enable Auto-Merge
if: ${{ steps.cpr.outputs.pull-request-number }}
run: gh pr merge --auto --squash "$PR_URL" || gh pr merge --squash "$PR_URL"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_URL: ${{ steps.cpr.outputs.pull-request-url }}
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,37 @@ ZIO HTTP is designed in terms of **HTTP as function**, where both server and cli
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](https://zio.dev/zio-cli) and ZIO HTTP.

## Installation

Setup via `build.sbt`:

```scala
libraryDependencies += "dev.zio" %% "zio-http" % "3.0.0-RC7"
libraryDependencies += "dev.zio" %% "zio-http" % "3.0.0-RC9"
```

**NOTES ON VERSIONING:**
Expand Down Expand Up @@ -91,7 +103,7 @@ object GreetingClient extends ZIOAppDefault {

## Documentation

Learn more on the [ZIO Http homepage](https://github.com/zio/zio-http)!
Learn more on the [ZIO Http homepage](https://zio.dev/zio-http)!

## Contributing

Expand Down
1 change: 1 addition & 0 deletions aliases.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ addCommandAlias("fmt", "scalafmt; Test / scalafmt; sFix;")
addCommandAlias("fmtCheck", "scalafmtCheck; Test / scalafmtCheck; sFixCheck")
addCommandAlias("sFix", "scalafix OrganizeImports; Test / scalafix OrganizeImports")
addCommandAlias("sFixCheck", "scalafix --check OrganizeImports; Test / scalafix --check OrganizeImports")
addCommandAlias("generateMediaTypes", "zioHttpTools/runMain zio.http.tools.GenerateMediaTypes")

onLoadMessage := {
import scala.Console._
Expand Down
11 changes: 11 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ lazy val aggregatedProjects: Seq[ProjectReference] =
zioHttpHtmx,
zioHttpExample,
zioHttpTestkit,
zioHttpTools,
docs,
)
}
Expand Down Expand Up @@ -267,6 +268,10 @@ lazy val zioHttpHtmx = (project in file("zio-http-htmx"))
.settings(
stdSettings("zio-http-htmx"),
publishSetting(true),
libraryDependencies ++= Seq(
`zio-test`,
`zio-test-sbt`,
),
)
.dependsOn(zioHttpJVM)

Expand All @@ -286,6 +291,12 @@ lazy val zioHttpExample = (project in file("zio-http-example"))
)
.dependsOn(zioHttpJVM, zioHttpCli, zioHttpGen)

lazy val zioHttpTools = (project in file("zio-http-tools"))
.settings(stdSettings("zio-http-tools"))
.settings(publishSetting(false))
.settings(runSettings(Debug.Main))
.dependsOn(zioHttpJVM)

lazy val zioHttpGen = (project in file("zio-http-gen"))
.settings(stdSettings("zio-http-gen"))
.settings(publishSetting(true))
Expand Down
6 changes: 3 additions & 3 deletions docs/guides/testing-http-apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Testing HTTP applications is a critical part of the development process. Utilizi

We have comprehensive documentation on [ZIO Test](https://zio.dev/reference/test/) which is worth reading to understand how to write tests using ZIO effects.

It is easy to test ZIO HTTP applications beacuse we can think of `HttpApp` as a function of `Request => ZIO[R, Response, Response]`. This means we can effortlessly provide a Request as input to the `HttpApp` and receive the corresponding Response as output using the runZIO method. By doing this we can test the behavior of the `HttpApp` in a controlled environment:
It is easy to test ZIO HTTP applications because we can think of `HttpApp` as a function of `Request => ZIO[R, Response, Response]`. This means we can effortlessly provide a Request as input to the `HttpApp` and receive the corresponding Response as output using the runZIO method. By doing this we can test the behavior of the `HttpApp` in a controlled environment:

```scala mdoc:silent:reset
import zio.test._
Expand All @@ -20,7 +20,7 @@ object ExampleSpec extends ZIOSpecDefault {

def spec = suite("http")(
test("should be ok") {
val app = Handler.ok.toHttpApp
val app = Handler.ok.toRoutes
val req = Request.get(URL(Path.root))
assertZIO(app.runZIO(req))(equalTo(Response.ok))
}
Expand Down Expand Up @@ -105,7 +105,7 @@ object TestServerExampleSpec extends ZIOSpecDefault {
test("test hello and fallback routes") {
for {
client <- ZIO.service[Client]
port <- ZIO.serviceWith[Server](_.port)
port <- ZIO.serviceWithZIO[Server](_.port)
testRequest = Request
.get(url = URL.root.port(port))
.addHeaders(Headers(Header.Accept(MediaType.text.`plain`)))
Expand Down
8 changes: 4 additions & 4 deletions docs/reference/endpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ In the above example, we defined an endpoint on the path `/books` that accepts a
After defining the endpoint, we are ready to implement it. We can implement it using the `Endpoint#implement` method, which takes a proper handler function that will be called when the endpoint is invoked and returns a `Route`:

```scala
val booksRoute = endpoint.implement(handler((query: String) => BookRepo.find(query)))
val booksRoute = endpoint.implement(query => BookRepo.find(query))
```

We can also generate OpenAPI documentation for our endpoint using the `OpenAPIGen.fromEndpoints` constructor:
Expand Down Expand Up @@ -261,13 +261,13 @@ object EndpointWithMultipleOutputTypes extends ZIOAppDefault {
.out[Quiz]

def run = Server.serve(
endpoint.implement(handler {
endpoint.implement(_ =>
ZIO.randomWith(_.nextBoolean)
.map(r =>
if (r) Right(Course("Introduction to Programming", 49.99))
else Left(Quiz("What is the boiling point of water in Celsius?", 2)),
)
})
)
.toRoutes).provide(Server.default, Scope.default)
}
```
Expand Down Expand Up @@ -417,7 +417,7 @@ case class Book(
The `OpenAPIGen.fromEndpoints` constructor generates OpenAPI documentation from the endpoints. By having the OpenAPI documentation, we can easily generate Swagger UI routes using the `SwaggerUI.routes` constructor:

```scala
val booksRoute = endpoint.implement(handler((query: String) => BookRepo.find(query)))
val booksRoute = endpoint.implement(query => BookRepo.find(query))
val openAPI = OpenAPIGen.fromEndpoints(title = "Library API", version = "1.0", endpoint)
val swaggerRoutes = SwaggerUI.routes("docs" / "openapi", openAPI)
val routes = Routes(booksRoute) ++ swaggerRoutes
Expand Down
Loading

0 comments on commit 3477c32

Please sign in to comment.