scala 在 Java 中使用 Akka 的 REST API
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14569205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
REST API with Akka in Java
提问by marothisu
I am trying to create my own REST-based API using Java and Akka. I have created my main algorithmic implementation using Akka already. My confusion is coming in the form of how to implement the REST part of this. Most examples and libraries I have seen are specifically for Scala, which I am at the moment trying to stay away from.
我正在尝试使用 Java 和 Akka 创建我自己的基于 REST 的 API。我已经使用 Akka 创建了我的主要算法实现。我的困惑在于如何实现其中的 REST 部分。我见过的大多数示例和库都是专门针对 Scala 的,我目前正试图远离它。
I see Spray is a good way to go, but I see it's supposed to be for Scala. However, I know Scala compiles down to Java Byte Code and Java should be able to call Scala and visa versa. Is it possible to do this with Spray? If so, are there any working examples or tutorials online? I am not having any luck anywhere.
我认为 Spray 是一个很好的方法,但我认为它应该用于 Scala。但是,我知道 Scala 可以编译为 Java 字节码,Java 应该能够调用 Scala,反之亦然。可以用喷雾做到这一点吗?如果是这样,是否有任何在线示例或教程?我在任何地方都没有运气。
Thanks for your help and time.
感谢您的帮助和时间。
回答by billerby
I would recommend you to use playframework 2.0. It is already integrated with akka and you can choose to write your code in Java or Scala. Its will be very easy to implement a REST-based API.
我建议您使用 playframework 2.0。它已经与 akka 集成,您可以选择用 Java 或 Scala 编写代码。实现基于 REST 的 API 将非常容易。
回答by Rob
Actually, I went down the same exact path: wanted to use Akka for REST-based services implementation and did not want to use Scala.
实际上,我走上了同样的道路:想使用 Akka 来实现基于 REST 的服务,而不想使用 Scala。
Akka can be used with Play-mini, which gives you the Sinatra-like REST mapping without any of the ui stuff (you don't need).
Akka 可以与 Play-mini 一起使用,它为您提供类似 Sinatra 的 REST 映射,而无需任何 ui 内容(您不需要)。
回答by Rob
You may also want to look at the Spray Framework http://spray.io/. It might be the lightweight alternative to Play Framework.
您可能还想查看喷雾框架http://spray.io/。它可能是 Play Framework 的轻量级替代品。
回答by Rakesh Waghela
Here is a github repo with Jersey 2 Rest Service using Akka actors for processing in a Java project based on Maven.
这是一个带有 Jersey 2 Rest Service 的 github 存储库,使用 Akka actor 在基于 Maven 的 Java 项目中进行处理。
回答by Mattis
I think you want to look at this:
我想你想看看这个:
https://www.typesafe.com/activator/template/akka-http-microservice
https://www.typesafe.com/activator/template/akka-http-microservice
Simple (micro)service which demonstrates how to accomplish tasks typical for REST service using Akka HTTP. Project includes: starting standalone HTTP server, handling simple file-based configuration, logging, routing, deconstructing requests, unmarshalling JSON entities to Scala's case classes, marshaling Scala's case classes to JSON responses, error handling, issuing requests to external services, testing with mocking of external services.
简单(微)服务,演示如何使用 Akka HTTP 完成典型的 REST 服务任务。项目包括:启动独立的 HTTP 服务器、处理简单的基于文件的配置、日志记录、路由、解构请求、将 JSON 实体解组到 Scala 的案例类、将 Scala 的案例类编组到 JSON 响应、错误处理、向外部服务发出请求、使用模拟测试的外部服务。
回答by Armen Arzumanyan
at the moment two modern microservices & REST technologies: Vert.x and dropwizard
目前有两种现代微服务和 REST 技术:Vert.x 和 dropwizard
回答by Tomer R.
Akka-HTTP is the defacto Spray 2.0 as this stackoverflow thread shows: Spray, Akka-http and Play, Which is the best bet for a new HTTP/REST project
Akka-HTTP 是事实上的 Spray 2.0,正如此 stackoverflow 线程所示: Spray、Akka-http 和 Play,这是新 HTTP/REST 项目的最佳选择
So, I would opt for choosing Akka-HTTP if REST based API for Akka was what you were looking for.
因此,如果您正在寻找基于 REST 的 Akka API,我会选择 Akka-HTTP。
回答by Rafael
There is an old entry (2010) on akka github for a akka-sample-rest-java example that would be really interesting. However it's removed in following versions, don't know why.
在 akka github 上有一个旧条目 (2010) 一个 akka-sample-rest-java 示例,这将非常有趣。但是在以下版本中被删除了,不知道为什么。
Since it has been unmaintained, most of the classes rely on old versions of akka and does not works with the most recent ones.
由于它一直没有维护,大多数类都依赖于旧版本的 akka,并且不适用于最新版本。

