Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Routes#serve Method #2801

Closed
khajavi opened this issue Apr 25, 2024 · 4 comments
Closed

Adding Routes#serve Method #2801

khajavi opened this issue Apr 25, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@khajavi
Copy link
Member

khajavi commented Apr 25, 2024

I would like to have a simple API with the following syntax:

import zio.http._

object MainApp extends ZIOAppDefault {
  def run =
    Routes {
      Method.GET / "hello" -> handler(Response.text("Hello, World!"))
    }
    .serve
    .provide(Server.default)
  
}
@khajavi khajavi added the enhancement New feature or request label Apr 25, 2024
@khajavi khajavi changed the title Add Routes#server Method Adding Routes#server Method Apr 25, 2024
@khajavi khajavi changed the title Adding Routes#server Method Adding Routes#serve Method Apr 25, 2024
@GrigoriiBerezin
Copy link
Contributor

GrigoriiBerezin commented May 6, 2024

Hello, you can do it like so

implicit class RouteOps[Env, Err <: Response](val routes: Routes[Env, Err]) extends AnyVal {
  def serve: URIO[Env with Server, Int] = Server.install(routes)
}

def run =
    Routes {
      Method.GET / "hello" -> handler(Response.text("Hello, World!"))
    }
    .serve
    .provide(Server.default)

@kyri-petrou
Copy link
Collaborator

@GrigoriiBerezin I think the point of this ticket is to streamline this for users so they don't have to write boilerplate code :)

@GrigoriiBerezin
Copy link
Contributor

Ok, I see, may create a MR for that 👍

@GrigoriiBerezin
Copy link
Contributor

#2829

@jdegoes jdegoes closed this as completed Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants