forked from zio/zio-http
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into deprecate-3.0
- Loading branch information
Showing
30 changed files
with
947 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
id: endpoint-scala3 | ||
title: "Endpoint Scala 3 Syntax" | ||
sidebar_label: "Endpoint Scala 3 Syntax" | ||
--- | ||
|
||
```scala | ||
import zio.http.* | ||
import zio.http.codec.* | ||
import zio.http.endpoint.* | ||
|
||
import java.util.UUID | ||
|
||
type NotFound[EntityId] = EntityId | ||
type EntityId = UUID | ||
|
||
val union: ContentCodec[String | UUID | Boolean] = | ||
HttpCodec.content[String] || HttpCodec.content[UUID] || HttpCodec.content[Boolean] | ||
|
||
val unionEndpoint = | ||
Endpoint(Method.GET / "api" / "complex-union") | ||
.outCodec(union) | ||
|
||
val unionWithErrorEndpoint | ||
: Endpoint[Unit, Unit, NotFound[EntityId] | String, UUID | Unit, AuthType.None] = | ||
Endpoint(Method.GET / "api" / "union-with-error") | ||
.out[UUID] | ||
.orOut[Unit](Status.NoContent) | ||
.outError[NotFound[EntityId]](Status.NotFound) | ||
.orOutError[String](Status.BadRequest) | ||
|
||
val impl = unionWithErrorEndpoint.implementEither { _ => | ||
val result: Either[NotFound[EntityId] | String, UUID | Unit] = Left("error") | ||
result | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.