Skip to content

Request mappings

Mariusz Kopylec edited this page Jun 22, 2024 · 9 revisions

Request mapping is a configuration that defines which and how incoming requests will be forwarded. Multiple request mappings can be added. The configuration from previous page will use request mapping named all requests mapping to forward incoming requests. Every request mapping must be named. The request mapping which will handle the incoming request is chosen by a regular expression that defines incoming request paths. If path regular expression is not set then the configured request mapping will handle all incoming requests. If the incoming request does not match any of request mappings' path regular expressions then it will be handled locally by the application. Sample configuration of request mapping's path regular expression can look like this:

import static com.github.mkopylec.charon.configuration.CharonConfigurer.charonConfiguration;
import static com.github.mkopylec.charon.configuration.RequestMappingConfigurer.requestMapping;

@Configuration
class CharonConfiguration {

    @Bean
    CharonConfigurer charonConfigurer() {
        return charonConfiguration()
                .add(requestMapping("mapping name")
                        .pathRegex("/path/.*"));
    }
}

For the above configuration, if the incoming request's path is /path/sub-path then it will be handled by mapping name request mapping. But if the incoming request's path is /some-other-path then it will be handled locally by the application, for example by a Spring @Controller if any exists. More things can be configured for request mapping. See further documentation for more details.

<< previous | next >>