com.vtence.molecule.routing.Router Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of molecule Show documentation
Show all versions of molecule Show documentation
A web micro-framework for Java
package com.vtence.molecule.routing;
import com.vtence.molecule.HttpMethod;
import java.util.ArrayList;
import java.util.Collection;
public class Router implements RouteBuilder {
private final Collection routes = new ArrayList();
public void build(RouteSet routeSet) {
for (DynamicRouteDefinition route : this.routes) {
routeSet.add(route.draw());
}
}
public RouteDefinition map(String path) {
return openRoute().map(path);
}
public RouteDefinition get(String path) {
return map(path).via(HttpMethod.GET);
}
public RouteDefinition post(String path) {
return map(path).via(HttpMethod.POST);
}
public RouteDefinition put(String path) {
return map(path).via(HttpMethod.PUT);
}
public RouteDefinition delete(String path) {
return map(path).via(HttpMethod.DELETE);
}
private RouteDefinition openRoute() {
DynamicRouteDefinition definition = DynamicRouteDefinition.route();
routes.add(definition);
return definition;
}
}