Skip to content

Instantly share code, notes, and snippets.

@joshuakfarrar
Last active February 11, 2019 19:02
Show Gist options
  • Save joshuakfarrar/ae2b4e46c72314f703124ac4cd7309ef to your computer and use it in GitHub Desktop.
Save joshuakfarrar/ae2b4e46c72314f703124ac4cd7309ef to your computer and use it in GitHub Desktop.
// RegistrationFormValidator.validateForm(form) returns Either[ValidationError, ValidRegistration]
// the expected return type of our HttpService[F] creator is F[Response[F]], so here we use .bimap
// and friends to finagle our validated form into that type.
val service: HttpService[F] = {
HttpService[F] {
case req @ POST -> Root / "users" =>
req.decode[RegistrationForm] { form =>
RegistrationFormValidator.validateForm(form).bimap(error => registrationFailed(error),
user => insertRegistration(User(UUID.randomUUID, user.email, user.password.bcrypt))
.map(registrationSucceeded).flatMap(identity)).merge
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment