All Projects → tokuhirom → Routes

tokuhirom / Routes

Path routing library for Java

Programming Languages

java
68154 projects - #9 most used programming language

Routes for Java

Build Status

This is a tiny routing library for Java.

Synopsis

Your WebAction.java

@FunctionalInterface
public interface WebAction {
	void call(ServletRequest req, ServletResponse res);
}

Your routing code.

	// Create routing rules.
	router = new WebRouter<WebAction>();
	router.get("/", RootController::index)
			.get("/sample-json", RootController::sampleJson);
			
	// Match
	RoutingResult rr = router.match("GET", "/sample-json");
	if (rr != null) {
		if (rr.methodAllowed()) {
			return res405();
		} else {
			WebAction dst = rr.getDestination();
			return dst.invoke();
		}
	} else {
		return res404();
	}

Path Patterns

/member/{memberId}

Will match %r{^/member/[a-zA-Z0-9._-]+$}.

/download/*

Will match %r{^/download/.*$}.

/blog/{articleId:[0-9]+}

Will match %r{^/blog/[0-9]+$}. You can specify regular expression as a path.

Dependencies

  • Java 8
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].