-
Notifications
You must be signed in to change notification settings - Fork 422
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
Add Armeria server interpreters #1830
Conversation
Motivation: [Armeria](https://armeria.dev/) is a reactive microservice framework. This PR includes Armeria server interpreters for Standard `Future`, Cats Effect, and ZIO. Modifications: - Add `Armeria{Future,Cats,Zio}ServerInterpreter` - Add various mapping for converting from and to Armeria types - Add document and examples Result: Users can choose Armeria as a server-side backend for tapir. Future work: Implement Armeria client intercepters as well.
...ria-server/cats/src/main/scala/sttp/tapir/server/armeria/cats/ArmeriaCatsServerOptions.scala
Outdated
Show resolved
Hide resolved
server/armeria-server/cats/src/main/scala/sttp/tapir/server/armeria/cats/TapirCatsService.scala
Outdated
Show resolved
Hide resolved
server/armeria-server/src/main/scala/sttp/tapir/server/armeria/ArmeriaServerOptions.scala
Outdated
Show resolved
Hide resolved
server/armeria-server/src/main/scala/sttp/tapir/server/armeria/ArmeriaServerRequest.scala
Outdated
Show resolved
Hide resolved
@@ -40,7 +41,10 @@ class ServerRejectTests[F[_], ROUTE]( | |||
testServer(endpoint.get.in("path"), "should return 404 for an unsupported method, when a single endpoint is interpreted")((_: Unit) => | |||
pureResult(().asRight[Unit]) | |||
) { (backend, baseUri) => | |||
basicRequest.post(uri"$baseUri/path").send(backend).map(_.code shouldBe StatusCode.NotFound) | |||
val statusCode = | |||
if (useMethodNotAllowedForUnsupportedMethod) StatusCode.MethodNotAllowed |
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.
isn't this functionality provided by the RejectInterceptor
? It would seem this should be independent of the interpreter used
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.
An unknown HTTP method is rejected at the routing level of Armeria before a TapirService
handles the request. So RejectInterceptor
can not handle the result. As a workaround, I can add an HTTP decorator of Armeria to replace "405 Method Not Allowed
with Not Found
.
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.
Ah as you extract the endpoint coordinates beforehand and provide them to armeria. I haven't read this code fragment yet entirely :)
Makes sense, if that's how Armeria works, let's keep it this way. Probably worth mentioning in the docs that the behavior here diverges from the other interpreters
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.
I removed HTTP methods specified in an Endpoint
from Route
of Armeria.
All HTTP methods are allowed at Armeria level so that RejectInterceptor
customizes the response of invalid requests.
A really solid PR, thanks! :) I've left some comments |
server/armeria-server/src/main/scala/sttp/tapir/server/armeria/ArmeriaBodyListener.scala
Outdated
Show resolved
Hide resolved
I also noticed that the tests are quite slow. I suppose that's because for each test, a new thread pool is created. Maybe there is a way to share these resources across tests? That's what happens e.g. in the netty interpreter (https://github.com/softwaremill/tapir/blob/master/server/netty-server/src/test/scala/sttp/tapir/server/netty/NettyFutureTestServerInterpreter.scala#L35) |
Yes. Let me specify shared pools for event loops and blocking task executors. |
I found out that Armeria already uses a |
I found out Armeria server always waits for 2 seconds to let the boss group gracefully finish all remaining tasks in the queue. |
Thanks :) |
Motivation:
Armeria is a reactive microservice framework.
This PR includes Armeria server interpreters for Standard
Future
, Cats Effect, and ZIO.Modifications:
Armeria{Future,Cats,Zio}ServerInterpreter
Result:
Users can choose Armeria as a server-side backend for tapir.
Future work:
Implement Armeria client interceptors as well.