Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Template for a Spring/Java/RESTeasy based REST service
branch: master

This branch is even with magiconair:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src/main
.gitattributes
.gitignore
README.md
pom.xml
rest-server.iml
rest-server.ipr

README.md

Overview

This is a simple REST service template which I've used in a number of projects. It is based on Spring and RESTEasy and with a lean DAO objects based on the Spring SimpleJDBCTemplate and RowMapper classes.

You can use Hibernate or other ORM tools if you like. In the end my preference was the leaner - the better. That's why this template is not using Hibernate.

The dependency management is done with Maven so you need to have that somewhere in your path. If that is not your cup of tea you can replace it with something else of course.

Architecture

If you have worked with Spring before then the architecture should look familiar. For the others I've compiled a short overview of the files and locations

src
└── main
    ├── java                    <-- java files live here
    │   └── com
    │       └── goleft
    │           └── rest
    │               ├── dao
    │               ├── entity
    │               ├── log
    │               ├── service
    │               └── util
    ├── resources               <-- config files live here
    ├── sql                     <-- sql files live here
    └── webapp                  <-- HTML files live here
        └── WEB-INF             <-- Spring config files live here 

MySQL setup

You need to create a database for the service to function. In the default configuration the service expects a database rest on localhost. You can change this in src/main/resources/config.properties

To create the database connect to your MySQL instance as root and run the following commands

mysql -h localhost -u root -p
mysql> create database rest;
mysql> grant all on rest.* to 'rest'@'localhost' identified by 'rest';
mysql> flush privileges;
mysql> quit;

Then load the database with

mysql -h localhost -urest -prest rest < src/main/sql/rest.sql

Project setup

As the final step you use maven to download the depedencies and build the .war file.

Run the following command to download all dependencies and to build the service.

mvn clean package

Then run this command to run the service.

mvn jetty:run

Now you should be able to access it under http://localhost:8080/rest/

Something went wrong with that request. Please try again.