Skip to content

jacobus/s4

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

S4 - Spray Slick Scala Start

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

Note, if you have used, or are planning to use this example to get started, and are interested in using Akka-HTTP instead of Spray, have a look at the this to get an idea of the type of changes required.

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

To get going:

  1. Clone the project

  2. Change into the project directory, type sbt and hit return

  3. Wait for stuff to start up and type test

To run the project as a service:

  1. Have a look at DBConfig.scala to see what database will be used (default PostgreSQL with a database called s4)

  2. Make sure you have PostgreSQL running and update the DBConfig.scala file to include your password.

  3. You can run the project by typing run

  4. Verify that it's running by visiting localhost:8080

  5. Now you can post some json to it (look at the tests for some valid examples)

Simple sample of file upload:

To test the upload function. With s4 running, open another terminal and go into the s4 directory. Once there, execute the following command:

curl -i -F "[email protected]" 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'.

Using an IDE:

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.

Contribute:

Pull requests are welcome!

Getting help:

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.

Updates:

I will tweet any significant change to the sample project.

Credits:

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.

About

Spray Slick Starter Stack

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published