A tiny HTTP router for [RxNetty] (https://github.com/ReactiveX/RxNetty).
rxnetty-router currently requires java8 and it's using [jauter] (https://github.com/sinetja/jauter) under the hood.
rxnetty-router-cors supplies a minimal CORS implementation. See DispatchTest for details
maven:
<repositories>
TBD
</repositories>
<dependencies>
<dependency>
<groupId>org.pk11.rxnetty</groupId>
<artifactId>rxnetty-router-core</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>org.pk11.rxnetty</groupId>
<artifactId>rxnetty-router-cors</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
import static org.pk11.rxnetty.router.Dispatch.using;
import static org.pk11.rxnetty.router.Dispatch.withParams;
(...)
HttpServer<ByteBuf, ByteBuf> server = HttpServer.newServer().start(
using(
new Router<ByteBuf, ByteBuf>()
.GET("/hello", new HelloHandler())
.GET("/article/:id", withParams((params, request, response)->{
response.setStatus(HttpResponseStatus.OK);
response.writeString("params:"+ params.get("id"));
return response.close();
}))
.GET("/public/:*", new ClassPathFileRequestHandler("www"))
.notFound(new Handler404())
)
);
See RouterTest for a full example.
import org.pk11.rxnetty.router.cors.Dispatch.CorsSettings;
import static org.pk11.rxnetty.router.cors.Dispatch.usingCors;
import static org.pk11.rxnetty.router.Dispatch.withParams;
(...)
HttpServer<ByteBuf, ByteBuf> server = HttpServer.newServer().start(
usingCors(
new CorsSettings(),
new Router<ByteBuf, ByteBuf>()
.register(router -> router.POST("/hello", new HelloHandler()))
.GET("/hello", new HelloHandler())
.GET("/article/:id", withParams((params, request, response) -> {
response.setStatus(HttpResponseStatus.OK);
response.writeString("params:"+ params.get("id"));
return response.close();
}))
.GET("/public/:*", new ClassPathFileRequestHandler("www"))
.notFound(new Handler404())
)
);
See DispatchTest for a full example.