Class Router
- java.lang.Object
-
- com.github.fmjsjx.libnetty.http.server.middleware.Router
-
- All Implemented Interfaces:
Middleware,java.util.function.BiFunction<HttpRequestContext,MiddlewareChain,java.util.concurrent.CompletionStage<HttpResult>>
public class Router extends java.lang.Object implements Middleware
AMiddlewarerouting requests.- Since:
- 1.1
- See Also:
Middleware,MiddlewareChain
-
-
Constructor Summary
Constructors Constructor Description Router()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Routeradd(HttpServiceInvoker service, java.lang.String path, io.netty.handler.codec.http.HttpMethod... methods)Add a new HTTP route with given parameters.Routeradd(java.lang.String path, HttpServiceInvoker service)Add a new "all method allowed" route with specified path and service.Routeradd(java.lang.String path, io.netty.handler.codec.http.HttpMethod method, HttpServiceInvoker service)Add a new HTTP route with given parameters.java.util.concurrent.CompletionStage<HttpResult>apply(HttpRequestContext ctx, MiddlewareChain next)Apply thisMiddlewareto the givenHttpRequestContext.Routerdelete(java.lang.String path, HttpServiceInvoker service)Add a new HTTP DELETE route with specified path and service.Routerget(java.lang.String path, HttpServiceInvoker service)Add a new HTTP GET route with specified path and service.Routerinit()Initial thisRouter.Routerpatch(java.lang.String path, HttpServiceInvoker service)Add a new HTTP PATCH route with specified path and service.Routerpost(java.lang.String path, HttpServiceInvoker service)Add a new HTTP POST route with specified path and service.Routerput(java.lang.String path, HttpServiceInvoker service)Add a new HTTP PUT route with specified path and service.Routerregister(java.lang.Object controller)Register a controller.<T> Routerregister(T controller, java.lang.Class<T> clazz)Register a controller.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.github.fmjsjx.libnetty.http.server.middleware.Middleware
close, onServerClosed
-
-
-
-
Method Detail
-
apply
public java.util.concurrent.CompletionStage<HttpResult> apply(HttpRequestContext ctx, MiddlewareChain next)
Description copied from interface:MiddlewareApply thisMiddlewareto the givenHttpRequestContext.- Specified by:
applyin interfacejava.util.function.BiFunction<HttpRequestContext,MiddlewareChain,java.util.concurrent.CompletionStage<HttpResult>>- Specified by:
applyin interfaceMiddleware- Parameters:
ctx- theHttpRequestContextobject of the current HTTP requestnext- theMiddlewareChainfor invoking the nextMiddleware- Returns:
- a
CompletionStage<HttpResult>
-
add
public Router add(HttpServiceInvoker service, java.lang.String path, io.netty.handler.codec.http.HttpMethod... methods)
Add a new HTTP route with given parameters.- Parameters:
service- an HTTP servicepath- the path pattern of the servicemethods- the array of the allowed HTTP methods- Returns:
- this
Router
-
add
public Router add(java.lang.String path, io.netty.handler.codec.http.HttpMethod method, HttpServiceInvoker service)
Add a new HTTP route with given parameters.- Parameters:
path- the path pattern of the servicemethod- the HTTP methodservice- an HTTP service- Returns:
- this
Router
-
add
public Router add(java.lang.String path, HttpServiceInvoker service)
Add a new "all method allowed" route with specified path and service.- Parameters:
path- the path pattern of the serviceservice- an HTTP service- Returns:
- this
Router
-
get
public Router get(java.lang.String path, HttpServiceInvoker service)
Add a new HTTP GET route with specified path and service.- Parameters:
path- the path pattern of the serviceservice- an HTTP service- Returns:
- this
Router
-
post
public Router post(java.lang.String path, HttpServiceInvoker service)
Add a new HTTP POST route with specified path and service.- Parameters:
path- the path pattern of the serviceservice- an HTTP service- Returns:
- this
Router
-
put
public Router put(java.lang.String path, HttpServiceInvoker service)
Add a new HTTP PUT route with specified path and service.- Parameters:
path- the path pattern of the serviceservice- an HTTP service- Returns:
- this
Router
-
patch
public Router patch(java.lang.String path, HttpServiceInvoker service)
Add a new HTTP PATCH route with specified path and service.- Parameters:
path- the path pattern of the serviceservice- an HTTP service- Returns:
- this
Router
-
delete
public Router delete(java.lang.String path, HttpServiceInvoker service)
Add a new HTTP DELETE route with specified path and service.- Parameters:
path- the path pattern of the serviceservice- an HTTP service- Returns:
- this
Router
-
register
public Router register(java.lang.Object controller)
Register a controller.This method is equivalent to:
ControllerBeanUtil.register(this, controller);- Parameters:
controller- the controller object- Returns:
- this
Router - See Also:
RouterUtil.register(Router, Object)
-
register
public <T> Router register(T controller, java.lang.Class<T> clazz)
Register a controller.This method is equivalent to:
ControllerBeanUtil.register(this, controller, clazz);- Type Parameters:
T- the type of the controller- Parameters:
controller- the controller objectclazz- the class of the type- Returns:
- this
Router - See Also:
RouterUtil.register(Router, Object, Class)
-
-