or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdfunctional-programming.mdhttp-client.mdindex.mdrequest-processing.mdview-resolution.mdwebsocket.md
tile.json

tessl/maven-org-springframework--spring-webflux

Spring WebFlux is a reactive web framework that provides a non-blocking, event-driven approach to building web applications and APIs.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.springframework/spring-webflux@6.2.x

To install, run

npx @tessl/cli install tessl/maven-org-springframework--spring-webflux@6.2.0

index.mddocs/

Spring WebFlux

Spring WebFlux is a reactive web framework that provides a non-blocking, event-driven approach to building web applications and APIs. Built on top of Project Reactor, it supports both functional and annotation-based programming models and is designed for high-concurrency scenarios where applications need to handle thousands of concurrent connections efficiently.

Package Information

  • Package Name: org.springframework:spring-webflux
  • Package Type: maven
  • Language: Java (with Kotlin support)
  • Installation: Add to your Maven dependencies:
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webflux</artifactId>
    <version>6.2.8</version>
</dependency>

For Gradle:

implementation 'org.springframework:spring-webflux:6.2.8'

Core Imports

import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.DispatcherHandler;
import org.springframework.web.reactive.socket.WebSocketHandler;
import org.springframework.web.reactive.config.EnableWebFlux;

Basic Usage

import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.reactive.function.server.RouterFunctions;
import static org.springframework.web.reactive.function.server.RequestPredicates.*;
import reactor.core.publisher.Mono;

// HTTP Client usage
WebClient client = WebClient.create("https://api.example.com");
Mono<String> response = client.get()
    .uri("/users/{id}", 123)
    .retrieve()
    .bodyToMono(String.class);

// Functional routing usage
RouterFunction<ServerResponse> route = RouterFunctions.route()
    .GET("/users/{id}", request -> {
        String id = request.pathVariable("id");
        return ServerResponse.ok().bodyValue("User: " + id);
    })
    .POST("/users", request -> 
        request.bodyToMono(User.class)
            .flatMap(this::saveUser)
            .flatMap(user -> ServerResponse.ok().bodyValue(user))
    )
    .build();

Architecture

Spring WebFlux is built around several key components:

  • Reactive Core: Built on Project Reactor (Mono/Flux) for non-blocking, asynchronous processing
  • Dispatcher Handler: Central request dispatcher similar to Spring MVC's DispatcherServlet
  • Handler Mappings: Route requests to appropriate handlers based on URL patterns, HTTP methods, etc.
  • Handler Adapters: Adapt different handler types (controllers, functions) to a common interface
  • Functional Programming Model: RouterFunction and HandlerFunction for composable request handling
  • WebClient: Non-blocking HTTP client with fluent API
  • WebSocket Support: Full reactive WebSocket implementation for real-time communication
  • View Resolution: Template engine integration for server-side rendering

Capabilities

Reactive HTTP Client

Non-blocking HTTP client with fluent API for making HTTP requests. Supports request/response customization, error handling, and reactive streams.

interface WebClient {
    RequestHeadersUriSpec<?> get();
    RequestHeadersUriSpec<?> head();
    RequestBodyUriSpec post();
    RequestBodyUriSpec put(); 
    RequestBodyUriSpec patch();
    RequestHeadersUriSpec<?> delete();
    RequestHeadersUriSpec<?> options();
    RequestBodyUriSpec method(HttpMethod method);
    Builder mutate();
    static WebClient create();
    static WebClient create(String baseUrl);
    static Builder builder();
}

HTTP Client

Functional Web Programming

Functional programming model using RouterFunction and HandlerFunction for composable request handling without annotations.

@FunctionalInterface
interface RouterFunction<T extends ServerResponse> {
    Mono<HandlerFunction<T>> route(ServerRequest request);
}

@FunctionalInterface  
interface HandlerFunction<T extends ServerResponse> {
    Mono<T> handle(ServerRequest request);
}

interface ServerRequest {
    HttpMethod method();
    URI uri();
    String path();
    <T> Mono<T> bodyToMono(Class<? extends T> elementClass);
    <T> Mono<T> bodyToMono(ParameterizedTypeReference<T> typeReference);
    String pathVariable(String name);
    Map<String, String> pathVariables();
}

Functional Programming

WebSocket Support

Full reactive WebSocket implementation supporting both client and server-side WebSocket connections with message handling.

interface WebSocketSession {
    String getId();
    Flux<WebSocketMessage> receive();
    Mono<Void> send(Publisher<WebSocketMessage> messages);
    boolean isOpen();
    Mono<Void> close();
}

@FunctionalInterface
interface WebSocketHandler {
    Mono<Void> handle(WebSocketSession session);
}

interface WebSocketClient {
    Mono<Void> execute(URI url, WebSocketHandler handler);
}

WebSocket Support

Configuration and Setup

Configuration classes and annotations for setting up WebFlux applications, including CORS, resource handling, and custom components.

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Import(DelegatingWebFluxConfiguration.class)
@interface EnableWebFlux {}

interface WebFluxConfigurer {
    default void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {}
    default void addCorsMappings(CorsRegistry registry) {}
    default void addResourceHandlers(ResourceHandlerRegistry registry) {}
    default void configureViewResolvers(ViewResolverRegistry registry) {}
}

Configuration

Request Processing Pipeline

Core framework components for request dispatching, handler mapping, and result processing in reactive web applications.

class DispatcherHandler implements WebHandler {
    Mono<Void> handle(ServerWebExchange exchange);
}

interface HandlerMapping {
    Mono<Object> getHandler(ServerWebExchange exchange);
}

interface HandlerAdapter {
    boolean supports(Object handler);
    Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler);
}

Request Processing

View Resolution and Templating

View resolution system supporting multiple template engines including FreeMarker and script templates for server-side rendering.

interface View {
    Mono<Void> render(Map<String, ?> model, MediaType contentType, ServerWebExchange exchange);
}

interface ViewResolver {
    Mono<View> resolveViewName(String viewName, Locale locale);
}

interface Rendering {
    String name();
    Map<String, Object> modelAttributes();
    HttpStatusCode status();
}

View Resolution

Types

// Core response types
abstract class ServerResponse {
    HttpStatusCode statusCode();
    HttpHeaders headers();
    Mono<Void> writeTo(ServerWebExchange exchange, Context context);
    
    static BodyBuilder ok();
    static BodyBuilder status(HttpStatusCode status);
    static BodyBuilder created(URI location);
    static BodyBuilder notFound();
}

// WebSocket message types
class WebSocketMessage {
    enum Type { TEXT, BINARY, PING, PONG }
    Type getType();
    DataBuffer getPayload();
    String getPayloadAsText();
}

class CloseStatus {
    static final CloseStatus NORMAL;
    static final CloseStatus GOING_AWAY;
    static final CloseStatus PROTOCOL_ERROR;
    
    int getCode();
    String getReason();
}

// Request/Response context
interface ServerWebExchange {
    ServerHttpRequest getRequest();
    ServerHttpResponse getResponse();
    Map<String, Object> getAttributes();
    WebSession getSession();
}