Showing posts with label lift. Show all posts
Showing posts with label lift. Show all posts

18 January 2013

Restful Web Service in Scala and Lift

I just put up the skeleton of a rest service, I hacked together in Scala and Lift... the code is up on my github: https://github.com/wbwarnerb/Scala-RestfulService

I can't take full credit, I used a variety of tutorials (cited in the readme) and came up with that code as my solution.

Currently it has hard coded data for a city (Burbank) and it sets up a restful url of:
.../api/city/
when Burbank is caught, it returns XML data.

I'd like this to get hooked into a database (the mysql "world" sample database) and I'd like to get CRUD actions running on the service, so I can post, delete and get various values.

But I got the skeleton done.

Getting Intellij Set up with Lift and Scala

I didn't find getting Scala set up too hard with Intellij... it was just the plugin. But getting Lift or other frameworks like Play set up with Intellij was a real beast.

I found a variety of information online and put it together as my steps to getting this working on Windows, with Intellij.  Without doing this, Intellij will not understand your imports like import net.liftweb._  and will complain about "Unknown symbol" or something like that.

What you will need installed is:
When you have all of this installed and on your windows env path, open a new console (note if your console was open while you were installing you'll need to restart it to pick up the path changes) and do the following:

1. Generating the Maven Archetype:
go into a folder of your choice and do:
mvn archetype:generate \
  -DarchetypeGroupId=net.liftweb \
  -DarchetypeArtifactId=lift-archetype-basic_2.9.1 \
  -DarchetypeVersion=2.4-M5 \
  -DarchetypeRepository=http://scala-tools.org/repo-snapshots \
  -DremoteRepositories=http://scala-tools.org/repo-snapshots \
  -DgroupId=com.company \
  -DartifactId=lift_test \
  -Dversion=1.0

On Windows, replace "\" with "^" for multi-line commands

2. Once done, run SBT in this folder with simply typing sbt and hitting ENTER.

3. In Intellij create a project and do an import project from external model (Maven) and pull this project in.


You can now write your code and save etc.  I didn't have to do anything special to get Scala to run... it was all set up from my previous work getting the scala plugin installed.

When you decide it's time to try the lift app out, you simply go to the lift project on the command line and type:
sbt update ~jetty-run