11

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.

marothisu
  • 123
  • 1
  • 1
  • 9

8 Answers8

2

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.

billerby
  • 1,977
  • 12
  • 22
  • +1 for Play2.0 Framework, it a part of the Typesafe stack fwiw. – lobster1234 Jan 28 '13 at 19:32
  • Isn't the entire Play Framework kind of heavy for something I'm making where I don't want to use any of the web framework, and only the REST capabilities? I thought this was the point of Play 2 Mini... – marothisu Jan 28 '13 at 20:32
  • I never looked at Play 2 Mini but at a first glimpse it looks like you should go for it if you only need the REST stuff. – billerby Jan 28 '13 at 20:40
2

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).

Rob
  • 11,446
  • 7
  • 39
  • 57
  • I had looked into Play 2 Mini. I downloaded it and tried to run their sample application (sbt), but got a compile error "object typesafe is not a member of package com object Global extends com.typesafe.play.mini.SetupJavaApplicationFor[com.example.App]"..I am new to this type of stuff..not sure how to get it working... – marothisu Jan 28 '13 at 19:28
  • Did you generate the app from their template? That's the thing to do, then just start changing the code from there. I went back and forth with their devs several times about their docs. They seemed open to feedback and resistant to change. :) – Rob Jan 28 '13 at 19:31
  • I basically downloaded it (came with Play 2 Mini) and then it said to do SBT on it, then run. Got that error....In reality I'm not familiar with SBT or anything. I just started using it when I started Akka type of stuff, but I run that from Eclipse anyway... – marothisu Jan 28 '13 at 19:47
  • This is it: http://typesafe.com/resources/getting-started/typesafe-stack/downloading-installing.html#template-projects-for-scala-akka-and-play create a project using that template... – Rob Jan 28 '13 at 20:44
  • and if you are feeling charitable, check my answer @marothisu – Rob Jan 28 '13 at 20:45
  • you’ll need the com.typesafe % config library on your classpath (that’s the error above anyway) – Roland Kuhn Jan 29 '13 at 12:22
2

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

2

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

Rakesh Waghela
  • 2,227
  • 2
  • 26
  • 46
1

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.

Mattis
  • 5,026
  • 3
  • 34
  • 51
0

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.

Rafael
  • 2,521
  • 2
  • 33
  • 59
0

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

Armen Arzumanyan
  • 1,939
  • 3
  • 30
  • 56
0

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.

Community
  • 1
  • 1
Tomer R.
  • 13
  • 3