Skip to content

Instantly share code, notes, and snippets.

@daharon
Last active June 23, 2025 13:15
Show Gist options
  • Save daharon/fc5c9f459cb15c22fc5916463e21c543 to your computer and use it in GitHub Desktop.
Save daharon/fc5c9f459cb15c22fc5916463e21c543 to your computer and use it in GitHub Desktop.
Endpoint output types
package dev.aharon.test.htmx_
import zio.http.endpoint.Endpoint
import zio.ZIO
import zio.http.{Handler, MediaType, Method, Path, Response, Status, URL}
import zio.schema.Schema
object EmailPasswordAuth:
private val validEmailPassword = (email = "[email protected]", password = "1234")
final case class EmailPasswordForm(email: String, password: String) derives Schema
val endpoint = Endpoint(Method.POST / "login")
.in[EmailPasswordForm](MediaType.application.`x-www-form-urlencoded`)
.out[String](Status.TemporaryRedirect)
.out[String](Status.Unauthorized)
.implementHandler(
Handler.fromFunction { form =>
if form.email == validEmailPassword.email && form.password == validEmailPassword.password
then Response.redirect(URL(Path("/app")))
else Response.unauthorized("Authentication Failed")
}
)
[error] -- [E007] Type Mismatch Error: .../src/main/scala/EmailPasswordAuth.scala:21:30
[error] 21 | then Response.redirect(URL(Path("/app")))
[error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error] | Found: zio.http.Response
[error] | Required: String
[error] -- [E007] Type Mismatch Error: .../src/main/scala/EmailPasswordAuth.scala:22:46
[error] 22 | else Response.unauthorized("Authentication Failed")
[error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error] | Found: zio.http.Response
[error] | Required: String
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment