leifoolsen / sensors

Example jersey/grizzly/collection+json for storing sensor's and sensor readings.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

REST server example with Collection+Json using Jersey/Grizzly

This example is far from done :)

Features

  • gzip encoding
  • using a hypermedia media-type like collection+json with jersey
  • caching
  • conditional PUT

Domain

The domain chosen for this example is pretty simple. We have two domain objects Sensor and SensorReadings.

Sensor: name, location and a list of readings SensorReadings: time, temperature and optionally humidity.

The domain was chosen for simplicity and also because it highlights the need for not directly exposing your domain objects as REST resources. In this particular case when we expose a sensor we also want the latest reading for it in the same resource.

Discussion

Not really sure on the best way to handle the transformation of data from the Service/DB to the Collection entity that the collection+json framework needs.

Where do you declare links and properties?

I think the best way will be to have a dedicated DTO class that is technology aware. In general I think technology agnostic DTO's are good, but in this case it is a very descriptive way of stating the intent.

So we use DTO's and annotations in them to state the intent of the item's in the Collection. But where do we state the template/queries and other links for the collection resource? I think the best place would be in the controller/resource object. That was you have two places where intent is stored.

About

Example jersey/grizzly/collection+json for storing sensor's and sensor readings.

License:MIT License


Languages

Language:Java 98.1%Language:Shell 1.9%