Skip to content

Commit

Permalink
update JVM binds #209
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethosa committed Dec 7, 2023
1 parent 56c6c67 commit 710e7be
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 3 deletions.
3 changes: 1 addition & 2 deletions bindings/java/src/main/java/com/hapticx/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.hapticx.data.WSConnection;
import com.hapticx.util.LibLoader;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -125,7 +124,7 @@ public void staticDirectory(String path, String directory, List<String> extensio
staticDirectory(this.serverId, path, directory, extensions);
}

public void staticDirectory(String path, String directory,String[] extensions) {
public void staticDirectory(String path, String directory, String[] extensions) {
staticDirectory(this.serverId, path, directory, Arrays.asList(extensions));
}

Expand Down
132 changes: 132 additions & 0 deletions bindings/java/src/main/java/com/hapticx/ServerBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package com.hapticx;


import java.util.List;

public class ServerBuilder {
private final Server server;

public ServerBuilder(String path, int port) {
this.server = new Server(path, port);
}

public ServerBuilder(String path) {
this.server = new Server(path, 5000);
}

public ServerBuilder(int port) {
this.server = new Server("127.0.0.1", port);
}

public ServerBuilder() {
this.server = new Server("127.0.0.1", 5000);
}

public ServerBuilder get(String path, Server.RequestCallback cb) {
this.server.get(path, cb);
return this;
}

public ServerBuilder post(String path, Server.RequestCallback cb) {
this.server.post(path, cb);
return this;
}

public ServerBuilder delete(String path, Server.RequestCallback cb) {
this.server.delete(path, cb);
return this;
}

public ServerBuilder put(String path, Server.RequestCallback cb) {
this.server.put(path, cb);
return this;
}

public ServerBuilder purge(String path, Server.RequestCallback cb) {
this.server.purge(path, cb);
return this;
}

public ServerBuilder link(String path, Server.RequestCallback cb) {
this.server.link(path, cb);
return this;
}

public ServerBuilder unlink(String path, Server.RequestCallback cb) {
this.server.unlink(path, cb);
return this;
}

public ServerBuilder copy(String path, Server.RequestCallback cb) {
this.server.copy(path, cb);
return this;
}

public ServerBuilder head(String path, Server.RequestCallback cb) {
this.server.head(path, cb);
return this;
}

public ServerBuilder options(String path, Server.RequestCallback cb) {
this.server.options(path, cb);
return this;
}

public ServerBuilder websocket(String path, Server.WebSocketCallback cb) {
this.server.websocket(path, cb);
return this;
}

public ServerBuilder middleware(Server.RequestCallback cb) {
this.server.middleware(cb);
return this;
}

public ServerBuilder notFound(Server.RequestCallback cb) {
this.server.notFound(cb);
return this;
}

public ServerBuilder route(String path, List<String> methods, Server.RequestCallback cb) {
this.server.route(path, methods, cb);
return this;
}

public ServerBuilder route(String path, String[] methods, Server.RequestCallback cb) {
this.server.route(path, methods, cb);
return this;
}

public ServerBuilder staticDirectory(String path, String directory, List<String> extensions) {
this.server.staticDirectory(path, directory, extensions);
return this;
}

public ServerBuilder staticDirectory(String path, String directory) {
this.server.staticDirectory(path, directory);
return this;
}

public ServerBuilder staticDirectory(String directory, List<String> extensions) {
this.server.staticDirectory(directory, extensions);
return this;
}

public ServerBuilder staticDirectory(String directory) {
this.server.staticDirectory(directory);
return this;
}

public ServerBuilder mount(String path, Server server) {
this.server.mount(path, server);
return this;
}

public void start() {
this.server.start();
}

public Server build() {
return this.server;
}
}
7 changes: 7 additions & 0 deletions bindings/java/src/main/java/com/hapticx/ServerDSL.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.hapticx

fun server(hostname: String = "127.0.0.1", port: Int = 5000, init: Server.() -> Unit): Server {
val server = Server(hostname, port)
server.init()
return server
}
Binary file modified bindings/java/src/main/resources/happyx.dll
Binary file not shown.
8 changes: 8 additions & 0 deletions bindings/java/src/test/java/com/hapticx/ServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ public void testServer() {
s.start();
}

@Test
public void builderTest() {
new ServerBuilder()
.get("/", req -> "Hello, world!")
.get("/html", req -> new HtmlResponse("<h1>Header</h1>"))
.start();
}

@Test
public void queriesTest() {
Query q = new Query("a", "b");
Expand Down
15 changes: 15 additions & 0 deletions bindings/java/src/test/java/com/hapticx/ServerTestKt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,19 @@ class ServerTestKt {

s.start()
}

@Test
fun withDsl() {
server("127.0.0.0", 5000) {
get("/") {
return@get "Hello, world!"
}

route("/some", listOf("GET", "POST")) {
return@route "Hello, world!"
}

start()
}
}
}
Binary file modified bindings/python/happyx/happyx.pyd
Binary file not shown.
2 changes: 1 addition & 1 deletion src/happyx/core/constants.nim
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const
# Framework version
HpxMajor* = 3
HpxMinor* = 7
HpxPatch* = 0
HpxPatch* = 1
HpxVersion* = $HpxMajor & "." & $HpxMinor & "." & $HpxPatch


Expand Down

0 comments on commit 710e7be

Please sign in to comment.