Skip to content

tokuhirom/routes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Path routing library for Java

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages