-2

I have a Java JSVC application in which I would like to expose a web/REST API from.

What is the simplest way to do so?

Every time I try to find a simple tutorial it wants me to install at least a framework and a web server (jersey, tomcat, Java EE, gradle, glassfish, spring and maven has been mentioned a lot)...

Is there a lightweight way to do it with as few dependencies as possible?

My app needs to be able to be deployed as a standalone daemon/service. It would be problematic if people had to set up a tomcat webserver and/or other stuff.

Isn't any Java app be able to bind to a port and listen for data?

  • You can always use a `ServerSocket` and handle everything yourself, but the advantage of all those pesky frameworks you don't want to use is that they already solved the problem for you (and provide a lot of extras you are likely going to need anyway). – Mark Rotteveel Mar 12 '16 at 12:00
  • I used a library called [Jetty](https://eclipse.org/jetty/) to help make a webserver. I didn't find it especially fantastic to work with, but it could do the basics. – joeytwiddle Mar 12 '16 at 12:08
  • I don't think you can get away from using *some* sort of framework, but they're not heavyweight or difficult to set up. Take a look at Spring Boot or Dropwizard. They both allow you to create a command line application exposing a Restful API in minutes. – sisyphus Mar 12 '16 at 12:20

1 Answers1

1

Many people around Spring say that Spring is exactly that - a lightweight server component for people that don't want to dive into the application server business.

Of course, a framework like Spring is still not lightweight; for example compared to a simple ServerSocket or the Jetty framework mentioned above.

But there is one thing to keep in mind: http traffic and REST do not come for free. Those terms means complexity; and dealing with that complexity is heavy lifting in order to get it right. Of course, it might be possible to pull together something on your own; but if your product attracts users; step by step you will be faced with more requirements. And all of a sudden you have to consider performance, security, standards ...

Thus: keep in mind that a "small" solution might solve your current problem. But that you might pretty quickly need "more than that". And all of a sudden, you are constantly re-inventing the wheel (and probably the wheel you are building is very much deficient compared to off-the-shelf solutions).

GhostCat
  • 137,827
  • 25
  • 176
  • 248