3

I am looking for the fastest way to create a Scala REST service. Ideally, I would like to build from scratch, learn the tricks of the trade before using a framework.

The REST service should serve JSON pulled from a MongoDB database. The web doesn't seem to be of much help, nor does the book on Scala by Martin Odersky.

flavian
  • 28,161
  • 11
  • 65
  • 105
  • "I would like to gain the best possible insight on what's going on behind the scenes" Which scene? – pedrofurla Dec 30 '12 at 23:00
  • You are right sir. Look at this beautiful HelloWorld in `Node.js`: `var http = require('http'); var server = http.createServer(function (request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.end("Hello World\n"); }); server.listen(8000); console.log("Server running at http://127.0.0.1:8000/");` - and please try to write something comparable, "without frameworks", in only true JavaScript ^) – idonnie Dec 31 '12 at 00:50
  • @idonnie, there are Scala frameworks that achieve the same thing as node.js. Except it's type safe and is in a sane language. – pedrofurla Dec 31 '12 at 12:32
  • @pedrofurla: JS is also a sane language, just with some unfortunate aspects because it was designed hastily. – Erik Kaplun Nov 18 '13 at 18:34

1 Answers1

4

I'm not aware of a tutorial or example that will give you exactly what you want, but I'm not really surprised at that. Anyone who wants to create a simple REST service would choose to use a framework, and you don't want to do that. By choosing to build something yourself from the ground up, you're choosing complexity - exactly the complexity that the frameworks exist to remove.

The same is true for Java - virtually nobody creates raw REST services on top of HttpServlet, because using a framework makes much more sense.

Having said that, creating a "raw" REST service in Scala would be virtually identical to doing so in Java. So find a Java/Maven example and do the small amount of work necessary to turn it into something that runs on top of Scala and SBT. This would be a good starting point.

Paul Butcher
  • 10,722
  • 3
  • 40
  • 44
  • Pretty much exactly what I would say except for use Maven instead. There's no need to climb the sbt learning curve just for this exercise. – sourcedelica Dec 31 '12 at 02:15
  • Also, you don't need to use a Scala framework - you can use a Java framework (see http://stackoverflow.com/questions/11756269/choosing-a-scala-web-framework/11759260#11759260) – sourcedelica Dec 31 '12 at 02:21
  • How can using *less* things make something *more complex*? Not using a framework makes it with very high probability simpler, given that the framework is highly likely going to do more than what you want, so those features need not be implemented. It can make it more *difficult* but that is a different thing – Samuel Rivas Oct 24 '15 at 07:42