This repository was archived by the owner on Mar 24, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Finch 0.10.0 #1933
Merged
Merged
Finch 0.10.0 #1933
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,38 +1,42 @@ | ||
| import java.net.InetSocketAddress | ||
| import java.text.{DateFormat, SimpleDateFormat} | ||
| import java.util.Date | ||
|
|
||
| import io.finch._ | ||
| import io.finch.route._ | ||
| import io.finch.response._ | ||
|
|
||
| import com.twitter.finagle.Service | ||
| import com.twitter.finagle.Httpx | ||
| import com.twitter.finagle.httpx.{Response, Request} | ||
|
|
||
| import com.twitter.finagle.Http | ||
| import com.twitter.finagle.stats.NullStatsReceiver | ||
| import com.twitter.finagle.tracing.NullTracer | ||
| import com.twitter.util.Await | ||
|
|
||
| import io.circe._ | ||
| import io.circe.generic.auto._ | ||
| import io.circe.jawn._ | ||
| import io.circe.syntax._ | ||
| import io.finch.response.EncodeResponse | ||
| import io.circe.{Decoder, Encoder, Json} | ||
|
|
||
| object WebServer extends App { | ||
| private val dateFormat: DateFormat = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z") | ||
|
|
||
| import io.finch.circe._ | ||
| val json = get("json") { | ||
| import io.finch.circe._ | ||
|
|
||
| case class Message(message: String) | ||
| Ok(Message("Hello, World!").asJson) | ||
| Ok(Json.obj("message" -> Json.string("Hello, World!"))) | ||
| .withHeader("Server" -> "finch") | ||
| .withHeader("Date" -> dateFormat.format(new Date())) | ||
| } | ||
|
|
||
| val plaintext = get("plaintext") { | ||
| "Hello, World!" | ||
| val plaintext: Endpoint[String] = get("plaintext") { | ||
| Ok("Hello, World!") | ||
| .withHeader("Server" -> "finch") | ||
| .withHeader("Date" -> dateFormat.format(new Date())) | ||
| .withContentType(Some("text/plain")) | ||
| } | ||
|
|
||
| val api: Service[Request, Response] = (json :+: plaintext).toService | ||
|
|
||
| Await.ready( | ||
| Httpx.serve(":9000", api) | ||
| Await.ready(Http.server | ||
| .withCompressionLevel(0) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry to bother again, but can you also disable stats receiver and tracer on a server instance? (in a same way as per #1941). .withStatsReceiver(NullStatsReceiver)
.withTracer(NullTracer) |
||
| .withStatsReceiver(NullStatsReceiver) | ||
| .withTracer(NullTracer) | ||
| .serve(":9000", (json :+: plaintext).toService) | ||
| ) | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put type here
Endpoint[io.circe.Json]and returnJson.obj("message" -> Json.string("Hello, World!"))directly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider it done.