https://github.com/soasada/popok
Minimal interfaces and default classes to build HTTP based services on top of undertow.
https://github.com/soasada/popok
http http-api http-server https jackson java json json-async undertow
Last synced: 10 days ago
JSON representation
Minimal interfaces and default classes to build HTTP based services on top of undertow.
- Host: GitHub
- URL: https://github.com/soasada/popok
- Owner: soasada
- License: apache-2.0
- Created: 2018-04-17T16:33:39.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2025-06-27T17:46:38.000Z (7 months ago)
- Last Synced: 2025-07-14T15:19:23.132Z (6 months ago)
- Topics: http, http-api, http-server, https, jackson, java, json, json-async, undertow
- Language: Java
- Homepage:
- Size: 288 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://maven-badges.herokuapp.com/maven-central/com.popokis/popok) [](https://lgtm.com/projects/g/soasada/popok/alerts/) [](https://lgtm.com/projects/g/soasada/popok/context:java)
# popok
Popok provides useful classes to work with HTTP based APIs, execute SQL queries via raw JDBC and JSON asynchronous parsing.
_Java 13 maven artifact_
```xml
com.popokis
popok
1.3.14
```
#### NOTE: Feel free to do a pull request or create an issue if you need any new features or find a bug.
## Simple HTTP API example
Popok use [undertow](https://github.com/undertow-io/undertow) as HTTP server, so creating a router is as simple as creating an undertow `HttpHandler`.
```java
// 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](https://github.com/soasada/undertow-vuejs)
## Bootstrapping a Server
[Server.java](/src/main/java/com/popokis/popok/http/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:
```java
/**
* 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)
```
```java
/**
* Enables HTTPs support. You have to specify the keystore path,
* popok will look inside 'resources' folder, looking for the 'keyStorePath'.
*/
enableHttps(String keyStorePath)
```
```java
/**
* Enables HTTP to HTTPs redirection. You have to specify which
* HTTP `3XX` code you want to use.
*/
redirectToHttps(int statusCode)
```
```java
/**
* Enables HTTP2 support.
*/
enableHttp2()
```
The mandatory fields, that popok needs for the properties configuration file, are:
* `server.http.port` to specify the HTTP port (an integer).
* `server.address` to specify the address of the server (an IP or `localhost`).
Additionally, you can specify optional configuration fields in order to activate HTTPs:
* `server.https.port` to specify the HTTPs port (an integer).
* `security.key.store.password` to specify the keystore password.
An example of `app.properties` file could be:
```java
server.http.port=8080
server.address=localhost
server.https.port=8443
security.key.store.password=password
```