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

Hello World example from readme seems not to work #1254

Open
KovaxG opened this issue Aug 12, 2020 · 2 comments
Open

Hello World example from readme seems not to work #1254

KovaxG opened this issue Aug 12, 2020 · 2 comments
Labels

Comments

@KovaxG
Copy link

KovaxG commented Aug 12, 2020

Hi, I really like the idea of finch, and I'm trying to test it out, but sadly I keep hitting obstacles.
First there was an issue with the versions, ( #1194) but I finally solved that. But now I can't get the example hello world to work either.

I'm trying

import io.finch._
import cats.effect.IO
import com.twitter.finagle.Http

object Server extends App with Endpoint.Module[IO] {
  val api: Endpoint[IO, String] = get("hello") { Ok("Hello, World!") }
  Http.server.serve(":8080", api.toServiceAs[Text.Plain])
}

but all I get is

Aug 12, 2020 1:16:58 PM com.twitter.finagle.Init$ $anonfun$once$1
INFO: Finagle version 20.3.0 (rev=e3fd6d1bd88c9ed7edeb98a6598e23800924c633) built at 20200308-110626

Process finished with exit code 0

I'm not sure if the problem is on my side or with the example.

@rpless
Copy link
Collaborator

rpless commented Aug 14, 2020

Hi @KovaxG I believe this is an issue with the docs. I think #1250 fixes it. I will try to take a look and merge it this weekend.
Basically, Http.server.serve is returning a future that represents the life time of the server. Because it is a future it returns immediately and then the program exits. You can wrap it in Await.ready to block it until the server shuts down like so:

Await.ready(Http.server.serve(":8080", api.toServiceAs[Text.Plain]))

@hderms
Copy link
Contributor

hderms commented Sep 15, 2020

I can confirm this is how we use Finch, as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants