Simple, mostly blank project to help you get started with a Spray REST service using Slick as persistence broker.
It's just a start, but you immediately get:
-
Spray
-
Akka
-
Slick
-
Logging
-
Testing
-
File Upload
-
HTTP Basic Authentication
-
A slice of cake
This project is nothing fancy, but tries to put skeleton code at the right places to start building a more serious project.
The cake pattern is used to allow multiple database backend support without code change. This complicates the code a little, but it will be worth it in the long run. For a basic Slick cake pattern example (and where I got some code from) have a look at the MultiDBCakeExample
-
Clone the project
-
Change into the project directory, type sbt and hit return
-
Wait for stuff to start up and type test
-
Have a look at DBConfig.scala to see what database will be used (default PostgreSQL with a database called s4)
-
Make sure you have PostgreSQL running and update the DBConfig.scala file to include your password.
-
You can run the project by typing run
-
Verify that it's running by visiting localhost:8080
-
Now you can post some json to it (look at the tests for some valid examples)
To test the upload function. With s4 running, open another terminal and go into the s4 directory. Once there, excecute the following command:
curl -i -F "imageupload=@testpic.png" http://127.0.0.1:8080/upload
This will upload the sample image 'testpic.png' to the server. The server will save the image to the same directory, but this time it will be called 'test.png'.
Both the Scala IDE (Eclipse) project generator and Idea project generator are included in plugins.sbt, so you can type gen-idea or eclipse in the SBT console to generate the project configuration for either of these great IDE's. Personally, I use both: Scala IDE for day-to-day development and it's amazing Scala Worksheet functionality, and Idea for it's superior search and replace.
Pull requests are welcome!
The spray-user forum and slick forum are both the best places to find help on the specific libraries. For questions or suggestions on specific to this project, please visit the S4 group.
I will tweet any significant change to the sample project.
This example borrows a great deal from examples provided by both the Spray and Slick authors.
Disclaimer: I am hoping this will serve as a nice example to get going, but you are using this code at your own risk.