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

io.github.kamilszewc.simplerouter.SimpleRouter Maven / Gradle / Ivy

There is a newer version: 0.6
Show newest version
package io.github.kamilszewc.simplerouter;

import java.util.ArrayList;
import java.util.List;

public class SimpleRouter {

    public enum Method {
        GET,
        POST,
        PUT,
        PATCH,
        DELETE
    }

    private List routes = new ArrayList<>();

    protected SimpleRouter() {
    }

    public void addRoute(Route route) {
        routes.add(route);
    }

    public void addRoute(Method method, String path, MethodHandler methodHandler) {
        Route route = new Route(method, path, methodHandler);
        routes.add(route);
    }

    public Object route(Request request) throws NoRoutingException {
        for (var route : routes) {

            try {
                var context = route.checkRouting(request);
                return route.callMethod(context);

            } catch (Exception ignore) {}
        }

        throw new NoRoutingException();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy