jetty.project
jetty.project copied to clipboard
Jetty 12 - Server/Handler DSL
Jetty version(s) 12+
Enhancement Description
The idea is to provide an easy to use, almost single-line, builder-like, DSL to build a Server instance and map HTTP methods and paths to Java method references.
Just syntactic sugar, but sometimes easier than figuring out what to write the next line, because an IDE will prompt what is available, and it's easier to pick .listen(), or .route().
A mocked API could be:
Server
.listen(8080, new HttpConnectionFactory())
.listen(8443, <a builder for ConnectionFactory>)
.routes()
.route(HttpMethod.GET, "/welcome", this::welcome)
.route(HttpMethod.POST, "/form", this::handleFormUpload)
.build()
.build()
.start();
A halfway step could be to make all our existing setters return this, so that they can be used in fluent style:
Server server = new Server();
server.
.addConnector(new ServerConnector(server, new HttpConnectionFactory()).setPort(8080));
.addConnector(new ServerConnector(server, new SslContextFacotory(), new SslConnectionFactory(), new HttpConnectionFactory()).setPort(8080));
.addHandler(new ContextHandlerCollection()
.addHandler(new ContextHandler("/foo").setHandler(...))
.addHandler(new ContextHandler("/bar").setHandler(...)))
.start();
A halfway step could be to make all our existing setters return this
I think it may mess up reflection so I would prefer to have that separated.
Also, I would like to avoid having to allocate ServerConnector (replaced by just listen()), ContextHandlerCollection (replaced by just route()) to ease up new users that don't have those concepts already.
Ok for something separate
I'm not so ok on calling connectors listeners, adding different names for the same thing will be confusing.
We could hide the CHC, but the DSLs of other servers don't do that.
I think we need to try a few experiments
This issue has been automatically marked as stale because it has been a full year without activity. It will be closed if no further activity occurs. Thank you for your contributions.