Popok provides useful classes to work with HTTP based APIs, execute SQL queries via raw JDBC and JSON asynchronous parsing.
Java 13 maven artifact
<dependency>
<groupId>com.popokis</groupId>
<artifactId>popok</artifactId>
<version>1.3.14</version>
</dependency>Popok use undertow as HTTP server, so creating a router is as simple as creating an undertow HttpHandler.
// Router
HttpHandler router = Handlers.path()
.addPrefixPath("/api/v1", Handlers.routing()
.get("/hello", (exchange) -> {
exchange.setStatusCode(StatusCodes.OK);
exchange.getResponseSender().send("Hello World!");
})
);
// Create and start the server
Server.builder(router)
.build()
.start();Are you looking for a more advanced example? Click here
Server.java it's just an Undertow wrapper class to add some functionality such as: HTTPs/HTTP2 support and HTTP to HTTPs redirection. To instantiate a Server you have to provide an undertow HttpHandler as router and use the builder API that provides you the following methods:
/**
* Sets a different name for the properties configuration file.
* If you don't use this method popok will look inside 'resources'
* folder, looking for 'app.properties' default file.
*/
propertiesFilename(String name)/**
* Enables HTTPs support. You have to specify the keystore path,
* popok will look inside 'resources' folder, looking for the 'keyStorePath'.
*/
enableHttps(String keyStorePath)/**
* Enables HTTP to HTTPs redirection. You have to specify which
* HTTP `3XX` code you want to use.
*/
redirectToHttps(int statusCode)/**
* Enables HTTP2 support.
*/
enableHttp2()The mandatory fields, that popok needs for the properties configuration file, are:
server.http.portto specify the HTTP port (an integer).server.addressto specify the address of the server (an IP orlocalhost).
Additionally, you can specify optional configuration fields in order to activate HTTPs:
server.https.portto specify the HTTPs port (an integer).security.key.store.passwordto specify the keystore password.
An example of app.properties file could be:
server.http.port=8080
server.address=localhost
server.https.port=8443
security.key.store.password=password