11
votes

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.

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.

Thanks for your help and time.

8

8 Answers

2
votes

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.

2
votes

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 can be used with Play-mini, which gives you the Sinatra-like REST mapping without any of the ui stuff (you don't need).

2
votes

You may also want to look at the Spray Framework http://spray.io/. It might be the lightweight alternative to Play Framework.

2
votes

Here is a github repo with Jersey 2 Rest Service using Akka actors for processing in a Java project based on Maven.

https://github.com/pofallon/jersey2-akka-java

1
votes

I think you want to look at this:

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.

0
votes

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.

https://github.com/akka/akka-modules/tree/v1.0/akka-samples/akka-sample-rest-java/src/main/java/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.

0
votes

at the moment two modern microservices & REST technologies: Vert.x and dropwizard

0
votes

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

So, I would opt for choosing Akka-HTTP if REST based API for Akka was what you were looking for.