Skip to content

A sample REST application written in Java (dropwizard, guice, jpa, hibernate, cors and more)

Notifications You must be signed in to change notification settings

gaquino/dropwizard-guice-jpa-seed

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

dropwizard-guice-jpa-seed

This a sample REST application written in Java. It's purpose is to create a generic project that can be used as a starting point for a new project, but also for learning efforts (I am building an open game database at www.oregami.org).

  • built on Dropwizard version 0.7.0
  • dependency injection with Google Guice
  • Hibernate / JPA 2.1 as database access framework
  • HSQLDB as database
  • "Session-per-HTTP-request" with Guice PersistentFilter
  • suport for cross-origin resource sharing
  • JPA entities with UUIDs as primary keys
  • Auditing/Version control of entities with hibernate envers
  • Basic authentication for DELETE at /task ("user" + "password")
  • Integration tests with rest-assured
  • a pattern for accessing and manipulation entities with HTTP REST calls (Resource => Service => DAO => entity)
  • a pattern for ServiceResult objects which contain ServiceErrorMessages (which can later be bound to web form fields in the client)

Feel free to suggest corrections, optimizations or extensions via pull requests!

road map / things to do

  • more complex entities
  • hypermedia / HATEOAS

Usage

  • Start the application with the class "ToDoApplication" with the parameters "server todo.yml".

  • List all tasks with:

      GET => http://localhost:8080/task
    
  • Add a new task with:

      POST => http://localhost:8080/task
    

    Header:

      Content-Type:application/json
    

    JSON-Body e.g. :

      {"name" : "task 1", "description" : "This is a description"}
    
  • Modify a task:

      PUT => http://localhost:8080/task/[id]
    

    Header:

      Content-Type:application/json
      Accept:application/json
    

    JSON-Body e.g.:

      {
      "id": "402880944687600101468760d9ea0000",
      "version": "0",
      "name": "task 1 with new name",
      "description": "This is an updated description",
      "finished": "false"
      }
    
  • Remove a task: you must authenticate for this call with basic authentication (user = "user" and password="password")

      DELETE => http://localhost:8080/task/[id]
    
  • List all revision numbers of a task with:

      GET => http://localhost:8080/task/[id]/revisions
    
  • Show a single task with:

      GET => http://localhost:8080/task/[id]      
    
  • Show a special revision of a single task with:

      GET => http://localhost:8080/task/[id]/revisions/[revisionNumber]
    

I recommend you use the great chrome extension Postman to make such HTTP calls!

About

A sample REST application written in Java (dropwizard, guice, jpa, hibernate, cors and more)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published