https://github.com/tim-zh/photon-paw
An easy and convenient lib to add HTML-based UI to a console app
https://github.com/tim-zh/photon-paw
circleci htmlunit ui undertow web
Last synced: 3 months ago
JSON representation
An easy and convenient lib to add HTML-based UI to a console app
- Host: GitHub
- URL: https://github.com/tim-zh/photon-paw
- Owner: tim-zh
- License: apache-2.0
- Created: 2018-07-19T14:23:50.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-04-13T17:19:50.000Z (almost 3 years ago)
- Last Synced: 2025-07-17T15:31:12.460Z (9 months ago)
- Topics: circleci, htmlunit, ui, undertow, web
- Language: Java
- Homepage:
- Size: 66.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [PhotonPaw](http://timzh.net/photon-paw/)
[](https://maven-badges.herokuapp.com/maven-central/net.timzh/photon-paw)
[](https://circleci.com/gh/tim-zh/photon-paw)
#### Backend Example:
```java
new net.timzh.photonpaw.PhotonPaw()
//optional, configure main port and websocket port
.ports(19081, 19082)
//set location of static resources if any, empty string to refer to jar resources
.resourcesRoot("")
//add additional routes if static resources are not enough
.bindPath("/test", request -> UiHttpResponse.of("application/javascript", "alert('custom routing')"))
//subscribe to events from ui by name
.handleCommand("a", (msg, out) -> System.out.println("command received"))
//subscribe to requests from ui that expect some response
.handleQuery("b", msg -> "server response")
//subscribe to events with dynamic names
.defaultHandler((msg, out) -> System.out.println("unknown event " + msg))
//execute some code after establishing a connection with ui
.start(out ->
//send an event to ui
out.send("b", "server command")
)
.println("ui server started")
.openBrowser("/index.html")
.waitForTabToUnload()
.stop();
```
#### Frontend Example:
```html
PhotonPaw
//subscribe to events from ui server by name
.handleCommand("a", msg => alert("command received"))
//subscribe to events with dynamic names
.defaultHandler((event, msg) => alert("unknown event " + event + " " + msg))
//execute some code after establishing the connection with ui server
.start().then(() => {
//send an event to ui server
PhotonPaw.send("b", "ui command");
//send a request to ui server and process the response
PhotonPaw.ask("c", "ui query").then(response => alert("query response received"));
});
```