Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

ailohq/rxnetty-router

 
 

Repository files navigation

rxnetty-router

rxnetty-router-core Download

rxnetty-router-cors Download

Build Status

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

How to Install

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>

Core Example

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.

CORS 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.

About

A tiny HTTP Router for RxNetty

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%