mist mist - 7 months ago 64
reST (reStructuredText) Question

Jackson restful service in a main method

Can I host a restful service in a main method? It doesn't have to be Jackson.

I looked around for examples, but couldn't find any. I remember that for Servlets I need a web server, but it would be awesome if I can host a web service in a main method. It's just a simple method.

The data is static (imagine a hashtable with 900k elements).It is loaded from a json file (long story).

The method serves one element from the hash table by key.


If you really want to go java route, take a look here. http://stackoverflow.com/a/3732328/6785908

Read from the json file and write it to the output stream in the handle method (Instead of String response = "This is the response";)

I would rather use nginx or httpd as the static file server.


"The method serves one element from the hash table by key." So, at this point I would strongly encourage you to use spring boot. It has an embedded servlet container, you can just run the main method (or java -jar .jar, if you have packaged it in jar) Added advantage: if you have to marshall an object to json using jackson, spring boot comes with it out of the box