As I mentioned in my previous post I came across Spark Framework and was intrigued that java might have finally reached the level of simplicity to make it viable as a prototyping language for rest services.
Just to start things off easy I went with a simple time service:
Line 2 is wiring up the public resources that will be used shortly. Line 3-4 is returning the current time in miliseconds for a GET to /time.
To keep things more interesting I decided to throw in another technology that has been a buzz lately but I haven’t had time to pick it until now. And that is React.
This is my first react app so it probably is a little messy but you have to start somewhere. Basically it starts of setting the currentTime to empty string and as soon as the component is bound it will make a request to our spark rest API. Once the result is received, currentTime will be updated which is where the magic of React comes in and updates the corresponding UI elements.
Just for good measure here is a docker file that bundles up this spark app: