107

We are thinking on moving our Rest API Server (it is inside the web service, on Symfony PHP) to Scala for several reasons: speed, no overhead, less CPU, less code, scalability, etc. I didn't know Scala until several days ago but I've been enjoying what I've been learning these days with the Scala book and all the blog posts and questions (it's not so ugly!)

I have the following options:

  • build the Rest API Server from scratch
  • use a tiny Scala web framework like Scalatra
  • use Lift

Some things that I will have to use: HTTP requests, JSON output, MySQL (data), OAuth, Memcache (cache), Logs, File uploads, Stats (maybe Redis).

What would you recommend?

Jim Ferrans
  • 30,582
  • 12
  • 56
  • 83
fesja
  • 3,313
  • 6
  • 30
  • 42

7 Answers7

89

In no particular order:

oluies
  • 17,694
  • 14
  • 74
  • 117
  • 1
    thanks! I will check on AKKA, as it seems to be very light and scalable – fesja Sep 09 '10 at 18:47
  • 1
    N.B I hope someone gets around of integrating or porting http://restfulie.caelum.com.br/ to Scala. One option now is using Restfulie as a frontend to Scala on JRuby. – oluies Sep 09 '10 at 18:49
  • 3
    +1, I use Akka at work to power a high-performance API server. The downside of using JAX-RS with Akka is that JAX-RS comes loaded with a ton of Java idiosyncrasies that don't fit very cleanly into a pure-Scala project. Still, Akka makes the entire deal worth it. – Max A. Sep 10 '10 at 02:28
  • 2
    Akka is a good choice. If you're serving JSON, have a look at Lift JSON. You can mix and match, no problem. – andyczerwonka Sep 22 '11 at 06:28
  • What happened with the HTTP module of AKKA in 2.0? – santiagobasulto Mar 06 '12 at 22:48
  • 1
    @santiagobasult I would say that Play! 2.0 and Play-mini! 2.0 happened – oluies Mar 06 '12 at 22:55
  • @oluies why do you listed Finagle? RPC and REST was always in controversy, or I'm missing something? – om-nom-nom May 28 '12 at 14:46
  • @om-nom-nom depends on what you are doing I guess here is two examples of rest services, restful... hmm maybe not ... https://github.com/robi42/heroku-finagle-rogue https://gist.github.com/1273845 – oluies May 28 '12 at 15:33
  • Spray website changed to spray.io – Jamil Oct 14 '12 at 22:07
  • The Pinky link is dead. – Nyx Apr 13 '13 at 17:19
  • If you choose Lift, you can find code examples to get you started for REST JSON APIs at http://fordevs.info/first-steps-in-using-scala-and-lift-for-a-server-project/ , http://exploring.liftweb.net/master/index-15.html#toc-Chapter-15 and http://stable.simply.liftweb.net/#toc-Chapter-5 – FreewheelNat May 23 '13 at 19:52
  • http4s(http://http4s.org/) is missing here. – B. S. Rawat Mar 18 '16 at 22:41
  • Akka documenentation moved to http://doc.akka.io/docs/akka-http/current/scala.html – Tim Child Feb 21 '17 at 19:50
  • Used Akka-Http, really simple for these kind of tasks. – Nav Aug 25 '17 at 13:50
23

I'm going to recommend Unfiltered. It's an idiomatic Web framework that does things "the Scala way" and is very beautiful.

Jan S.
  • 10,328
  • 3
  • 31
  • 36
Max A.
  • 4,842
  • 6
  • 29
  • 27
14

Take a look at Xitrum (I'm its author), it provides everything you listed. Its doc is quite extensive. From README:

Xitrum is an async and clustered Scala web framework and web server on top of Netty and Hazelcast:

  • Annotation is used for URL routes, in the spirit of JAX-RS. You don't have to declare all routes in a single place.
  • Async, in the spirit of Netty.
  • Sessions can be stored in cookies or clustered Hazelcast.
  • In-process and clustered cache, you don't need separate cache servers.
  • In-process and clustered Comet, you don't need a separate Comet server.
rath
  • 3,655
  • 1
  • 40
  • 53
Ngoc Dao
  • 1,501
  • 3
  • 18
  • 27
7

I would add two more options: akka with built-in JAX-RS support, and simply using JAX-RS directly (probably the Jersey implementation). While arguably less "Scala-y" than others (relying upon annotations to bind parameters and paths), JAX-RS is a joy to use, cleanly solving all of the problems of web service coding with minimal footprint. I've not used it via akka, I would anticipate it being excellent there, getting impressive scalability via it's continuation-based implementation.

Dave Griffith
  • 20,435
  • 3
  • 55
  • 76
  • thanks! I will check on AKKA with JAX-RS as @Brent and you said. It really seems to be very light with minimal footprint which is really important for an API, if you want to go really fast. – fesja Sep 09 '10 at 18:49
  • 1
    You'll have to use JAX-RS 2.0 (which is currently beta) to get the scalability as the older versions rely on nasty threadlocal (that is thread pausing and resuming are not supported). – Adam Gent Apr 25 '12 at 19:34
3

Take a look at Finch, a Scala combinator library for building Finagle HTTP services. Finch allows you to construct complex HTTP endpoints out of the number of predefined basic blocks. Similarly to parser combinators, Finch endpoints are easy to reuse, compose, test, and reason about.

Vladimir Kostyukov
  • 2,492
  • 3
  • 21
  • 30
3

All good answers so far. One point in Lift's favor is its RestHelper, which can make it quite easy to write short, elegant API methods. In addition, all the other things you want to do should be quite straight-forward to implement in Lift. That being said, Memcache might be not be necessary.

pr1001
  • 21,727
  • 17
  • 79
  • 125
  • thanks! why don't you think memcache is necessary? It depends of course, but we have several queries that are very likely to be done constantly, so it's time we win and less load on the database. – fesja Sep 09 '10 at 18:46
  • I'm really just going off of what David Pollak said yesterday. Basically, the caching within Lift removes many use-cases of memcache. Here's his message and there are a few other posts in the thread about memcache: http://groups.google.com/group/scala-base/msg/4b11cbd357bfecf0 – pr1001 Sep 10 '10 at 10:49
2

A little late on the scene but I would definitely recommend using Bowler framework for creation of REST API's. It small, to the point and automatic case class conversion support!

cracked_all
  • 1,331
  • 1
  • 11
  • 26