Spring Web module providing web application infrastructure including HTTP integration, servlet filters, Spring web MVC framework, and reactive web stack support
npx @tessl/cli install tessl/maven-org-springframework--spring-web@6.2.0Spring Web module provides foundational web infrastructure including HTTP abstractions, web client capabilities, servlet integration, reactive web support, and web-related utilities. It serves as the foundation for both Spring MVC (servlet-based) and Spring WebFlux (reactive) web frameworks.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.2.8</version>
</dependency>// HTTP abstractions
import org.springframework.http.*;
import org.springframework.http.client.*;
// Web clients
import org.springframework.web.client.RestTemplate;
import org.springframework.web.client.RestClient;
// Message conversion
import org.springframework.http.converter.*;
import org.springframework.http.codec.*;
// Web binding and annotations
import org.springframework.web.bind.annotation.*;
// Reactive web support
import org.springframework.web.server.*;
import org.springframework.web.reactive.function.client.*;
// Web utilities
import org.springframework.web.util.*;import org.springframework.web.client.RestTemplate;
import org.springframework.http.*;
// Create a REST client
RestTemplate restTemplate = new RestTemplate();
// Simple GET request
String result = restTemplate.getForObject(
"https://api.example.com/users/{id}",
String.class,
123
);
// POST request with body
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<User> request = new HttpEntity<>(user, headers);
ResponseEntity<User> response = restTemplate.postForEntity(
"https://api.example.com/users",
request,
User.class
);
// Modern fluent API with RestClient
RestClient restClient = RestClient.create();
User user = restClient.get()
.uri("https://api.example.com/users/{id}", 123)
.retrieve()
.body(User.class);The Spring Web module is organized around several key architectural components:
HttpEntity, ResponseEntity, HttpHeaders) for building web applicationsEssential HTTP types for building request/response entities, working with headers, status codes, and media types.
// Core HTTP entity types
class HttpEntity<T> {
HttpEntity(T body);
HttpEntity(MultiValueMap<String, String> headers);
HttpEntity(T body, MultiValueMap<String, String> headers);
HttpHeaders getHeaders();
T getBody();
boolean hasBody();
}
class ResponseEntity<T> extends HttpEntity<T> {
ResponseEntity(HttpStatusCode status);
ResponseEntity(T body, HttpStatusCode status);
HttpStatusCode getStatusCode();
static ResponseEntity<T> ok(T body);
static ResponseEntity<Void> noContent();
}
class RequestEntity<T> extends HttpEntity<T> {
RequestEntity(HttpMethod method, URI url);
RequestEntity(T body, HttpMethod method, URI url);
HttpMethod getMethod();
URI getUrl();
}Comprehensive HTTP client support including RestTemplate, modern RestClient, and client infrastructure.
// Modern fluent client API
interface RestClient {
RequestHeadersUriSpec<?> get();
RequestBodyUriSpec post();
RequestBodyUriSpec put();
static RestClient create();
static RestClient create(String baseUrl);
}
// Traditional template-based client
class RestTemplate implements RestOperations {
RestTemplate();
<T> T getForObject(String url, Class<T> responseType, Object... uriVariables);
<T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Object... uriVariables);
<T> T postForObject(String url, Object request, Class<T> responseType, Object... uriVariables);
}HTTP message converters for servlet applications and reactive codecs for streaming applications.
// Message converter interface
interface HttpMessageConverter<T> {
boolean canRead(Class<?> clazz, MediaType mediaType);
boolean canWrite(Class<?> clazz, MediaType mediaType);
List<MediaType> getSupportedMediaTypes();
T read(Class<? extends T> clazz, HttpInputMessage inputMessage);
void write(T t, MediaType contentType, HttpOutputMessage outputMessage);
}
// Reactive message reader/writer
interface HttpMessageReader<T> {
boolean canRead(ResolvableType elementType, MediaType mediaType);
Flux<T> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints);
Mono<T> readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints);
}Annotation-driven web development with parameter binding, validation, and controller configuration.
// Core web annotations
@RequestMapping(value = "/api/users", method = RequestMethod.GET)
@GetMapping("/api/users/{id}")
@PostMapping("/api/users")
@RequestParam(value = "name", required = false, defaultValue = "unknown")
@PathVariable("id")
@RequestBody
@ResponseBody
// Controller configuration
@RestController
@ControllerAdvice
@ExceptionHandler(value = UserNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)Non-blocking web server infrastructure for building reactive applications with WebFlux.
// Core reactive web interfaces
interface WebHandler {
Mono<Void> handle(ServerWebExchange exchange);
}
interface ServerWebExchange {
ServerHttpRequest getRequest();
ServerHttpResponse getResponse();
Map<String, Object> getAttributes();
Mono<WebSession> getSession();
Principal getPrincipal();
}
// WebFilter for reactive request processing
interface WebFilter {
Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain);
}URI building, HTML escaping, pattern matching, CORS support, and other web utilities.
// URI building utilities
class UriComponentsBuilder implements UriBuilder {
static UriComponentsBuilder fromPath(String path);
static UriComponentsBuilder fromUri(URI uri);
UriComponentsBuilder path(String path);
UriComponentsBuilder queryParam(String name, Object... values);
URI build(Object... uriVariables);
}
// Web service client support
class HttpServiceProxyFactory {
static HttpServiceProxyFactory.Builder builder();
<S> S createClient(Class<S> serviceType);
}// HTTP method enumeration
enum HttpMethod {
GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE;
boolean matches(String method);
static HttpMethod resolve(String method);
}
// HTTP status codes
enum HttpStatus implements HttpStatusCode {
OK(200), CREATED(201), NO_CONTENT(204),
BAD_REQUEST(400), UNAUTHORIZED(401), NOT_FOUND(404),
INTERNAL_SERVER_ERROR(500);
int value();
String getReasonPhrase();
boolean is2xxSuccessful();
boolean is4xxClientError();
static HttpStatus valueOf(int statusCode);
}
// Media type representation
class MediaType extends MimeType {
static final MediaType APPLICATION_JSON;
static final MediaType APPLICATION_XML;
static final MediaType TEXT_PLAIN;
static final MediaType MULTIPART_FORM_DATA;
MediaType(String type, String subtype);
boolean includes(MediaType other);
static MediaType parseMediaType(String mediaType);
}
// HTTP headers management
class HttpHeaders implements MultiValueMap<String, String> {
HttpHeaders();
void setAccept(List<MediaType> acceptableMediaTypes);
void setContentType(MediaType mediaType);
void setContentLength(long contentLength);
MediaType getContentType();
long getContentLength();
}