Package ninja

Interface Router

  • All Known Implementing Classes:
    RouterImpl

    public interface Router
    • Method Detail

      • getRouteFor

        Route getRouteFor​(String httpMethod,
                          String uri)
        Get the route for the given method and URI
        Parameters:
        httpMethod - The method
        uri - The URI
        Returns:
        The route
      • getReverseRoute

        @Deprecated
        String getReverseRoute​(Class<?> clazz,
                               String methodName)
        Deprecated.
        Reverse routing in the Router is not validated and does not URL-escape path or query parameters. Use ninja.ReverseRouter to build your reverse routes.
        Retrieves the reverse route for this controllerClass and method. Does not work with routes that contain placeholders. Use getReverseRoute(Class, String, Map) in that case
        Parameters:
        clazz - The controllerClass e.g. ApplicationController.class
        methodName - the methodName of the class e.g. "index"
        Returns:
        The final url (without server, and without any prefixes)
      • getReverseRoute

        @Deprecated
        String getReverseRoute​(Class<?> clazz,
                               String methodName,
                               Map<String,​Object> parameterMap)
        Deprecated.
        Reverse routing in the Router is not validated and does not URL-escape path or query parameters. Use ninja.ReverseRouter to build your reverse routes.
        Retrieves the reverse route for this controllerClass and method. The map contains pairs of url parameters. Eg. a raw route like "/person/{id} will become /person/1 when the map contains a pair like "id, "1".
        Parameters:
        clazz - The controllerClass e.g. ApplicationController.class
        methodName - the methodName of the class e.g. "index"
        map - The map containing pairs with replacements for placeholders. It's a String Object map so that it matches the map used to render a page. to get the value "toString()" is called on the object. Make sure that works for your object or simply use a String. If the raw uri does not contain the placeholders they will be added as query parameters ?key=value&key2=value2 and so on
        Returns:
        The final url (without server, and without any prefixes)
      • getReverseRoute

        @Deprecated
        String getReverseRoute​(Class<?> clazz,
                               String methodName,
                               Object... parameterMap)
        Deprecated.
        Reverse routing in the Router is not validated and does not URL-escape path or query parameters. Use ninja.ReverseRouter to build your reverse routes.
        Retrieves the reverse route for this controllerClass and method. The map contains pairs of url parameters. Eg. a raw route like "/person/{id} will become /person/1 when the map contains a pair like "id, "1".
        Parameters:
        clazz - The controllerClass e.g. ApplicationController.class
        methodName - the methodName of the class e.g. "index"
        parameterMap - The map containing pairs with replacements for placeholders. Always supply key and value pairs. Key as strings, Values as objects. To get the value "toString()" is called on the object. Make sure that works for your object or simply use a String. If the raw uri does not contain the placeholders they will be added as query parameters ?key=value&key2=value2 and so on
        Returns:
        The final url (without server, and without any prefixes)
      • getReverseRoute

        @Deprecated
        String getReverseRoute​(Class<?> controllerClass,
                               String controllerMethodName,
                               Optional<Map<String,​Object>> parameterMap)
        Deprecated.
        Reverse routing in the Router is not validated and does not URL-escape path or query parameters. Use ninja.ReverseRouter to build your reverse routes.
        Retrieves the reverse route for this controllerClass and method. The map contains pairs of url parameters. Eg. a raw route like "/person/{id} will become /person/1 when the map contains a pair like "id, "1".
        Parameters:
        clazz - The controllerClass e.g. ApplicationController.class
        methodName - the methodName of the class e.g. "index"
        parameterMap - An optinal map containing pairs with replacements for placeholders. Always supply key and value pairs. Key as strings, Values as objects. To get the value "toString()" is called on the object. Make sure that works for your object or simply use a String. If the raw uri does not contain the placeholders they will be added as query parameters ?key=value&key2=value2 and so on
        Returns:
        The final url (without server, and without any prefixes)
      • getReverseRoute

        @Deprecated
        String getReverseRoute​(MethodReference controllerMethodRef)
        Deprecated.
        Reverse routing in the Router is not validated and does not URL-escape path or query parameters. Use ninja.ReverseRouter to build your reverse routes.
      • getReverseRoute

        @Deprecated
        String getReverseRoute​(MethodReference controllerMethodRef,
                               Map<String,​Object> parameterMap)
        Deprecated.
        Reverse routing in the Router is not validated and does not URL-escape path or query parameters. Use ninja.ReverseRouter to build your reverse routes.
      • getReverseRoute

        @Deprecated
        String getReverseRoute​(MethodReference controllerMethodRef,
                               Object... parameterMap)
        Deprecated.
        Reverse routing in the Router is not validated and does not URL-escape path or query parameters. Use ninja.ReverseRouter to build your reverse routes.
      • getReverseRoute

        @Deprecated
        String getReverseRoute​(MethodReference controllerMethodRef,
                               Optional<Map<String,​Object>> parameterMap)
        Deprecated.
        Reverse routing in the Router is not validated and does not URL-escape path or query parameters. Use ninja.ReverseRouter to build your reverse routes.
      • compileRoutes

        void compileRoutes()
        Compile all the routes that have been registered with the router. This should be called once, during initialization, before the application starts serving requests.
      • getRoutes

        List<Route> getRoutes()
        Returns the list of compiled routes.
      • getRouteForControllerClassAndMethod

        Optional<Route> getRouteForControllerClassAndMethod​(Class<?> controllerClass,
                                                            String controllerMethodName)
      • METHOD

        RouteBuilder METHOD​(String method)
        To match any http method. E.g. METHOD("PROPFIND") would route PROPFIND methods.
        Parameters:
        method - The http method like "GET" or "PROPFIND"
        Returns:
        the routeBuilder for chaining.