Package io.muserver

Class ContextHandlerBuilder

    • Constructor Detail

      • ContextHandlerBuilder

        public ContextHandlerBuilder()
    • Method Detail

      • withPath

        public ContextHandlerBuilder withPath​(java.lang.String path)
        Sets the path to serve from.

        If a null or empty path is given, then it is as if the child handlers are not added to a context.

        Parameters:
        path - The path, such as api or /api/ etc
        Returns:
        Returns the current builder.
      • addHandler

        public ContextHandlerBuilder addHandler​(MuHandlerBuilder handler)

        Adds a request handler relative to the context of this builder.

        Note that handlers are executed in the order added to the builder, but all async handlers are executed before synchronous handlers.

        Parameters:
        handler - A handler builder. The build() method will be called on this to create the handler.
        Returns:
        The current Mu-Server Handler.
        See Also:
        addHandler(Method, String, RouteHandler)
      • addHandler

        public ContextHandlerBuilder addHandler​(MuHandler handler)

        Adds a request handler relative to the context of this builder.

        Note that handlers are executed in the order added to the builder, but all async handlers are executed before synchronous handlers.

        Parameters:
        handler - The handler to add.
        Returns:
        The current Mu-Server Handler.
        See Also:
        addHandler(Method, String, RouteHandler)
      • addHandler

        public ContextHandlerBuilder addHandler​(Method method,
                                                java.lang.String uriTemplate,
                                                RouteHandler handler)
        Registers a new handler that will only be called if it matches the given route info (relative to the current context).
        Parameters:
        method - The method to match, or null to accept any method.
        uriTemplate - A URL template, relative to the context. Supports plain URLs like /abc or paths with named parameters such as /abc/{id} or named parameters with regexes such as /abc/{id : [0-9]+} where the named parameter values can be accessed with the pathParams parameter in the route handler.
        handler - The handler to invoke if the method and URI matches.
        Returns:
        Returns the server builder