Skip to main content

@Rest and @RestOp

This page is a consolidated reference for the attributes of the three annotations that configure a REST resource:

All three live in the org.apache.juneau.rest.server package of the juneau-rest-server module. @Rest is applied to classes (@Target(TYPE)); @RestOp and the verb annotations are applied to methods (@Target(METHOD)); all are @Inherited. @Mixin has an empty @Target and can only be used as a value of @Rest(mixinDefs).

Unless stated otherwise, string attributes support SVL variables. Tri-state attributes are strings taking "true", "false" or "" (the default, meaning "inherit from the enclosing level").

@Rest attributes​

Identity, mounting and composition​

AttributeTypeDescription
pathStringResource path. Child-to-parent search. Only effective when the class is registered directly as a top-level resource; when the class is a mixin the host's path governs. See Path Variables.
pathsString[]Additional top-level mount paths. Each element is SVL-resolved and then comma-split.
childrenClass<?>[]Child resources, each mounted under its own URL subtree. See Child Resources.
childrenDefsChild[]Rich child definitions (host-side seed form of children).
mixinsClass<?>[]Operation-provider classes whose @RestOp methods are composed into this resource. See Mixin Sub-Contexts.
mixinDefsMixin[]Rich mixin definitions with host-side overrides. See @Mixin attributes below.
mergeResponseProcessorsIntoHostbooleanMixin-declared opt-in: when this class is composed as a mixin via a plain mixins= reference, fold its own responseProcessors into the host's chain. Default false.
lazyChildrenStringOpt the parent into deferred (first-invocation) construction of its children.
eagerInitStringEagerly initialize framework-managed memoizers during RestContext construction.
configStringLocation of the configuration file. The keyword SYSTEM_DEFAULT refers to Config.getSystemDefault(). See Configuration Files.
messagesStringLocation of the resource bundle for this class.
staticFilesClass<? extends StaticFiles>Static-file provider. Default StaticFiles.Void.class.
authenticatorClass<? extends RestAuthenticator>Resource-level authenticator. Default RestAuthenticator.Null.class. See Authenticator.

Marshalling and content negotiation​

AttributeTypeDescription
serializersClass<? extends Serializer>[]Serializers for response bodies.
parsersClass<?>[]Parsers for request bodies.
encodersClass<? extends Encoder>[]Compression encoders (e.g. gzip). See Encoders.
convertersClass<? extends RestConverter>[]Class-level response converters.
producesString[]Supported Accept media types, overriding those inferred from the serializers.
consumesString[]Supported Content-Type media types, overriding those inferred from the parsers.
partSerializerClass<? extends HttpPartSerializer>Part serializer for headers, query/form parameters and URI parts. Default HttpPartSerializer.Void.class.
partParserClass<? extends HttpPartParser>Part parser for headers, query/form parameters and URI parts. Default HttpPartParser.Void.class.
defaultAcceptStringDefault Accept header when not on the request.
defaultContentTypeStringDefault Content-Type header when not on the request.
defaultCharsetStringDefault character encoding when not on the request.
maxInputStringMaximum allowed request input size, in bytes.
allowedSerializerOptionsString[]Serializer session option keys that clients are allowed to set. See Session Options.
allowedParserOptionsString[]Parser session option keys that clients are allowed to set. See Session Options.
debugMarshallingStringTri-state opt-in to REST-driven serializer/parser debug behavior.

Defaults and request parameters​

AttributeTypeDescription
defaultRequestHeadersString[]Default request headers used when not sent by the client.
defaultRequestAttributesString[]Default request attributes used when not already set.
defaultResponseHeadersString[]Default response headers used when not set by the method.
headerParamsHeader[]Default definitions for @Header method parameters across the class.
queryParamsQuery[]Default definitions for @Query method parameters across the class.
formDataParamsFormData[]Default definitions for @FormData method parameters across the class.
pathParamsPath[]Default definitions for @Path method parameters across the class.
allowedHeaderParamsStringHeaders (e.g. Accept, Content-Type) that may be passed as URL query parameters.
allowedMethodParamsStringHTTP methods that may be requested through a method URL parameter. "*" means all. On a safe request (GET, HEAD, OPTIONS, TRACE) an admitted method is honored only if it is safe or its operation is declared read=true; otherwise the request is refused with 405. See Overloading HTTP Methods.
allowedMethodHeadersStringHTTP methods that may be requested through an X-Method, X-HTTP-Method-Override, X-HTTP-Method or X-Method-Override header. "*" means all. Empty (off) by default. Conflicting overrides are refused with 400. The same safe-request rule as allowedMethodParams applies. See Overloading HTTP Methods.
disableContentParamStringSet to true to disable the content URL parameter on PUT and POST requests.
clientVersionHeaderStringName of the header carrying the client version (see @RestOp(clientVersion)).

For the allowed*Params/allowedMethodHeaders attributes, the value "NONE" (case-insensitive) suppresses inheriting a value from a parent class.

Processing pipeline, security and runtime​

AttributeTypeDescription
guardsClass<? extends RestGuard>[]Guards applied to all operations of the class. See Guards.
roleGuardStringRole expression required to access operations, e.g. "ROLE_ADMIN".
rolesDeclaredStringComma-delimited list of all possible user roles.
responseProcessorsClass<? extends ResponseProcessor>[]Processors that convert returned POJOs into HTTP responses.
restOpArgsClass<? extends RestOpArg>[]Additional Java method parameter resolvers. See Java Method Parameters.
problemDetailsStringTri-state opt-in to RFC 7807 / RFC 9457 application/problem+json error responses. See Problem Details.
renderResponseStackTracesStringRender stack traces in HTTP response bodies when errors occur.
virtualThreadsStringTri-state opt-in to per-request virtual-thread dispatch (Java 21+; silently ignored with a warning on older JVMs).
asyncTimeoutMillisStringTimeout for CompletableFuture-returning handlers. Default 30,000 ms; "0" disables. On timeout the response is 504 Gateway Timeout. See Async Dispatch.
asyncCompletionExecutorStringName of the Executor bean on which CompletableFuture completion callbacks are run.
observabilityStringPer-resource observability opt-in/opt-out. See Observability.
noInheritString[]Property names for which less-derived contributions are not inherited (see below).

Documentation and URI resolution​

AttributeTypeDescription
titleString[]Servlet title; populates the Swagger title.
descriptionString[]Servlet description; populates the Swagger description.
siteNameStringSite name applied to the entire site.
swaggerSwaggerSwagger metadata (which uses @Contact, @License, @Tag; see Annotations).
swaggerProviderClass<? extends SwaggerProvider>Swagger provider. Default SwaggerProvider.Void.class.
openApiProviderClass<? extends OpenApiProvider>OpenAPI 3.1 provider. Default OpenApiProvider.Void.class.
uriAuthorityStringOverrides the authority path for this resource and its children.
uriContextStringOverrides the context path for this resource and its children.
uriRelativityStringHow relative URIs are interpreted by serializers.
uriResolutionStringHow relative URIs are resolved by serializers.

noInherit tokens​

On @Rest, accepted values are allowedParserOptions, allowedSerializerOptions, allowedHeaderParams, allowedMethodHeaders, allowedMethodParams, disableContentParam, renderResponseStackTraces, problemDetails, debugMarshalling, eagerInit, lazyChildren, clientVersionHeader, uriAuthority, uriContext, uriRelativity and uriResolution. On a class used as a mixin, the token set additionally includes serializers, parsers, encoders, converters, responseProcessors, restOpArgs, guards, partSerializer, partParser and messages, and blocks the host-to-mixin inheritance walk for that property. The noInherit attribute itself is never inherited.

@RestOp and verb-annotation attributes​

@RestOp is the general form. The verb annotations fix the HTTP method and therefore do not have a method attribute. Their value attribute is a path-only shorthand, whereas @RestOp(value) takes the combined "METHOD /path" form.

Example
// All equivalent:
@RestOp(method="PUT", path="/{propertyName}")
@RestOp("PUT /{propertyName}")
@RestPut("/{propertyName}")
@RestPut(path="/{propertyName}")

Attributes available on every operation annotation​

@RestOp, @RestGet, @RestPut, @RestPost, @RestDelete, @RestPatch and @RestOptions all provide:

AttributeTypeDescription
valueStringShorthand: "METHOD /path" on @RestOp, path only on the verb annotations.
pathString[]Path pattern(s). See Path Patterns.
clientVersionStringClient version range (e.g. "[0,1.0)", "1.0") matched against @Rest(clientVersionHeader).
guardsClass<? extends RestGuard>[]Guards for this operation.
roleGuardStringRole expression for this operation.
rolesDeclaredStringDeclared roles.
encodersClass<? extends Encoder>[]Compression encoders.
defaultAcceptStringDefault Accept header.
defaultCharsetStringDefault character encoding.
defaultRequestAttributesString[]Default request attributes.
defaultRequestHeadersString[]Default request headers.
defaultResponseHeadersString[]Default response headers.
allowedSerializerOptionsString[]Allowed serializer session option keys.
allowedParserOptionsString[]Allowed parser session option keys.
noInheritString[]Properties not inherited from @Rest. On operations the accepted values are allowedSerializerOptions, allowedParserOptions, problemDetails and debugMarshalling.
problemDetailsStringTri-state override of @Rest(problemDetails).
debugMarshallingStringTri-state override of @Rest(debugMarshalling).
observabilityStringTri-state override of @Rest(observability).
asyncCompletionExecutorStringExecutor bean name for async completion.
descriptionString[]Swagger operation description.
swaggerOpSwaggerSwagger operation metadata.
matchersClass<? extends RestMatcher>[]RestMatcher classes that let several Java methods share a method and path. See Matchers.
summaryStringSwagger operation summary.
defaultRequestQueryDataString[]Default query parameters used when not sent by the client.
metricName, metricTagsStringName and tags for the metrics recorded for this operation.

Availability of the remaining attributes​

A Y means the attribute is declared on that annotation (derived directly from the annotation sources).

Attribute@RestOp@RestGet@RestPut@RestPost@RestDelete@RestPatch@RestOptions
methodY------
serializersYYYY-YY
convertersYYYY-YY
producesYYYY-YY
parsersY-YY-Y-
consumesY-YY-Y-
maxInputY-YY-Y-
defaultContentTypeY-YY-Y-
defaultRequestFormDataY-YY-Y-
virtualThreadsY------
asyncTimeoutMillisY------

Reading the matrix: body-consuming attributes (parsers, consumes, maxInput, defaultContentType, defaultRequestFormData) are not available on @RestGet, @RestDelete or @RestOptions; response-shaping attributes (serializers, converters, produces) are not available on @RestDelete. virtualThreads and asyncTimeoutMillis can currently only be set per-operation on the general @RestOp annotation (both can also be set resource-wide on @Rest).

Operation-specific attributes​

AttributeDescription
methodThe HTTP method name. Besides the standard names: "*" matches any method (use @Method or RestRequest.getMethod() to tell them apart); "" auto-detects from the Java method name (defaulting to GET); "RRPC" marks a remote-proxy interface method; any other value is an overloaded method selected with the &method= URL parameter (on a safe request, only when read=true). See Inferred HTTP Methods and Paths and Overloading HTTP Methods.
readDeclares that a custom method only reads, so an override on a safe request (GET ?method=VIEW) may reach it. Accepted only on custom methods: POST, PUT, PATCH, DELETE, CONNECT, "*", "RRPC" or @Mutating fail at startup. See Overloading HTTP Methods.
virtualThreadsTri-state override of @Rest(virtualThreads).
asyncTimeoutMillisOverride of @Rest(asyncTimeoutMillis).

@Mixin attributes​

@Mixin is used only inside @Rest(mixinDefs=...). It names a mixin class and lets the host override selected @Rest-level settings for that mixin's endpoints without editing the mixin class.

Example
@Rest(
mixinDefs=@Mixin(type=FooMixin.class, guards=AdminGuard.class)
)
public class MyResource extends BasicRestServlet { ... }
AttributeTypeDescription
typeClass<?>Required. The mixin class to compose into the host.
mergeIntoHostbooleanOpt-in (default false): additionally append the mixin's own list-shaped @Rest attributes to the host's chains, so the host's own operations see them too.
pathStringHost-chosen mount prefix for the mixin's endpoints.
pathsString[]Host-chosen multiple mount prefixes.
noInheritString[]Inheritance-cutoff list for this mixin's sub-context (same tokens as @Rest(noInherit)). Authoritative over the override slots.

Override slots mirroring @Rest attributes of the same name:

ShapeAttributesSemantics
List-shapedguards, converters, encoders, serializers, parsers, responseProcessors, restOpArgs, defaultRequestHeaders, defaultResponseHeaders, defaultRequestAttributes, produces, consumesAppended after the host chain the mixin inherits.
Replace-shapedpartSerializer, partParser, defaultAccept, defaultContentType, defaultCharset, maxInput, roleGuard, rolesDeclared, messagesThe host override wins when set.

Host-only attributes (path, paths, children) are never folded into the host by mergeIntoHost. See Mixin Sub-Contexts for the full inheritance semantics and Mixins and Multi-Mount Paths for composition examples.

The following annotations are documented elsewhere but are often used alongside the ones above: