All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vtence.molecule.routing.Router Maven / Gradle / Ivy

There is a newer version: 0.15.0
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy