Skip to content

yswang0927/java-radixtree-url-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

java-radixtree-url-router

高性能Web-URL路由定义注册和匹配算法,从 https://github.com/gin-gonic/gin/blob/master/tree.go 翻译过来。

支持静态路由和动态路由:

  • 静态路由:/api/users
  • 命名参数动态路由:/api/users/:userId
  • 通配符参数动态路由:/api/actions/*actionName

用法:

Router router = new Router();
// 注册URL路由
router.get("/api/users", HandlersChain);
router.get("/api/users/:userId", HandlersChain);
router.post("/api/users", HandlersChain);
router.put("/api/users/:userId", HandlersChain);

// 测试路由匹配
RouteInfo routeInfo = router.match("GET", "/api/users");
System.out.println(routeInfo);

routeInfo = router.match("GET", "/api/users/10010");
System.out.println(routeInfo);

routeInfo = router.match("POST", "/api/users");
System.out.println(routeInfo);

routeInfo = router.match("PUT", "/api/users/10010");
System.out.println(routeInfo);

routeInfo = router.match("DELETE", "/api/users/10010");
System.out.println(routeInfo);

测试用例参见:ExampleTest.java

About

基于RadixTree算法的URL路由注册和匹配算法,从https://github.com/gin-gonic/gin/blob/master/tree.go翻译过来

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published