API Summary
This chapter lists the whole API surface, each entry pointing at the chapter that describes it.
Every published package is @NullMarked with JSpecify, so a parameter or return value excludes null unless its signature says @Nullable.
Tools that read JSpecify, such as NullAway and IntelliJ IDEA, report a null that reaches a non-null parameter.
What App provides
-
Routes:
get,post,put,patch,delete,head,options, each also as(path, description, handler), andpath(prefix, group → …); patterns and matching order in Routing -
Introspection:
routes()reports every registered route asRoute(method, path, description), in registration order.guards()reports the filters and error handlers beside them asGuard.BeforeRequest(path),Guard.BeforeRoute(path),Guard.AfterRoute(path),Guard.Error(status), andGuard.ResponseFilter().spider-silk-openapiturns the route list into an OpenAPI 3.1 document -
Filters:
beforeRequest(filter)/beforeRequest(path, filter)before routing,beforeRoute(filter)/beforeRoute(path, filter), same forafterRoute, andresponseFilter(filter)for every response, the ones no after-filter sees included -
Logging:
requestLogger((request, completion) → …), with the servlet status, elapsed time, response definition, transmission failure, and the exception the request was answered for inRequestCompletion; see Request Logging -
Errors:
exception(Type, handler), where the most specific registered type wins and anHttpExceptionreaches only a handler for its own type or a subtype,error(HttpStatus, handler) -
Response-wide concerns:
cors(Cors),gzip()/gzip(Gzip),securityHeaders()/securityHeaders(SecurityHeaders). Each is off until named, and applies to every answer including static files and errors, which is why they are not filters; see CORS, Compression, and Security -
Rendering and assets:
templates(renderer),staticFiles(classpathRoot),staticFiles(StaticFiles…). jte overclasspath:/jteandclasspath:/publicat the root are the defaults, so neither has to be called.StaticFiles.directory(path)serves a directory on disk instead of the classpath, several roots given at once are read in order, andprecompressed()answers with a.bror.gzsibling where a build left one.FreeMarkerTemplates,HandlebarsTemplates, andThymeleafTemplatesareTemplateRendererimplementations in modules of their own -
Server:
start()/start(port),stop(),join(),port(),server(factory). Registration closes while anAppServletserves the application, however it was started: a route, filter, or setting added then throwsIllegalStateException, andstop()opens it again.Cors,Gzip,SecurityHeaders, andStaticFilesare copied when they are registered
What WebRequest provides
-
Request info:
method(),path(),header(name),headers(name)for a repeated header,headers()for all of them,contentType(),queryString(),isSecure(),scheme(),host(),remoteAddress(), andraw()for the servlet request itself.host()carries the port when it is not the scheme’s default, soscheme(),host(), andpath()rebuild the absolute URL -
The matched route:
route(), theRoutethat answered, with its pattern and description; null before routing and where no route matched, see Route Introspection -
Path variables:
pathParam,pathParamLong,pathParamEnum, andpathParam(name, parser)for any other type. A name the pattern never declared throwsIllegalStateException, not a 400. A\{name*}tail binds the rest of the path with its slashes, and""when it matched nothing -
Parameters:
param(400 when missing),paramOrNull(null when missing),paramLong,paramBoolean(trueorfalseonly),paramEnum, each with a(…, default)form for optional parameters;params(name)for repeated values -
Any other type:
param(name, parser)andparam(name, parser, default), where the parser is aFunction<String, T>such asUUID::fromStringorLocalDate::parse. A parser that throwsIllegalArgumentExceptionorDateTimeExceptionanswers 400 naming the parameter -
One source only:
queryParam(name)andformParam(name)require a value and answer 400 when absent.queryParamOrNull(name)andformParamOrNull(name)return null when absent. Parser overloads are required unless a(…, parser, default)supplies a default -
Query vs. form:
queryParam,queryParams,formParam,formParams -
Content negotiation:
accepts(types…)answers with the type the caller prefers out of the ones offered, 406 when it will take none of them;acceptedTypes()for the parsedAcceptheader -
Cookies the client sent:
cookie(name),cookies() -
Body:
body(),bodyJson(),bodyJson(reader)(400 on a body the reader rejects). The text is read once and kept, so every call answers the whole body -
Multipart uploads:
file(name)(400 when absent),fileOrNull(name)(null when absent),files(name)for a field that carries several.UploadedFileanswersfileName(),contentType(),size(),bytes(),asText(),inputStream(), andwriteTo(path) -
Body, unread:
bodyStream()andbodyReader()hand it over for a parser from another library, and neither mixes with the kept text: whichever goes second throwsIllegalStateException.bodyNdjson(reader)reads newline-delimited JSON lazily, and answers 400 naming the line; see Large JSON and NDJSON and External JSON Binding -
Session:
sessionAttr(key, Class<T>)reads under a named type and fails on that line naming the key and both types,sessionAttr(key)leaves the cast to the call site,setSessionAttr(key, value)writes,removeSessionAttr(key)removes one, andinvalidateSession()ends the session -
Flash:
flash(key, value), read exactly once withflashed(key)on the request after a redirect, and a null value removes the key as it does for a session attribute -
Errors:
errorMessage()inside anerror(status, handler)handler
What WebResponse provides
-
Bodies:
html,text,json(raw),json(JsonValue),json(value, writer),bytes(contentType, data),template(name),template(name, model),stream(contentType, out → …),file(path),sse(stream → …),raw((req, res) → …) -
file(path)reads the content type from the name and the length from the file. A path that is not a readable regular file throwsUncheckedIOException, so a 404 for a missing file is the handler’s line to write -
Bodies written a value at a time:
jsonArray(sink → …)for an array too big to hold, andndjson(sink → …)for one value per line. Both are astreambody underneath, and the writer runs outside handler exception handling -
Statuses:
empty(),empty(HttpStatus),noContent(),redirect(location),redirect(location, HttpStatus) -
Building on:
status,header,withoutHeader(name),contentType,vary(field),attachment,body,cookie(name, value),cookie(name, value, maxAge),cookie(Cookie),removeCookie -
Reading back:
status(),header(name),headers(),cookies(),body(). Header names compare without regard to case, and one field holds one value however many spellings set it. A header that must be sent twice is written throughraw; see Headers
See The Response for the shape of body() and the lambda families.