{title:'RestContext', created:'9.0.0'}

The {@link oajr.RestContext} object is the workhorse class for all of the configuration of a single REST resource class. It's by-far the most important class in the REST API.

Every class annotated with @Rest ends up with an instance of this object. The object itself is read-only and unchangeable and is initialized with all of the various annotations pulled from the class and methods. All functionality available through annotations have programmatic equivalents through the builder of this class.

The {@link oajr.RestContext.Builder} class extends {@link oaj.BeanContext.Builder} allowing you to programmatically set any properties defined on that builder class. It also implements {@link jakarta.servlet.ServletConfig}

To access this object, simply pass it in as a constructor argument or in an INIT hook:

| // Option #1 - Pass in through constructor. | public MyResource(RestContext.Builder builder) { | builder | .beanContext(x -> x.swaps(TemporalCalendarSwap.Rfc1123DateTime. class)) | .debugEnablement(CONDITIONAL); | } | | // Option #2 - Use an init hook. | @RestInit | public void init(RestContext.Builder builder) throws Exception { | builder | .beanContext(x -> x.swaps(TemporalCalendarSwap.Rfc1123DateTime. class)) | .debugEnablement(CONDITIONAL); | }

This class is vast. Combined with {@link oaj.rest.RestOpContext} (which is the equivalent per-method context), these classes define the entire configuration and workflow of the REST API.

There are multiple ways to programmatically alter how RestContext behaves. The most straightforward are the following builder methods which are direct equivalents to values defined on the {@link oaj.rest.annotation.Rest} annotation:

- {@link oaj.rest.RestContext.Builder}
  - {@link oaj.rest.RestContext.Builder#allowedHeaderParams(String) allowedHeaderParams}
  - {@link oaj.rest.RestContext.Builder#allowedMethodHeaders(String) allowedMethodHeaders}
  - {@link oaj.rest.RestContext.Builder#allowedMethodParams(String) allowedMethodParams}
  - {@link oaj.rest.RestContext.Builder#clientVersionHeader(String) clientVersionHeader}
  - {@link oaj.rest.RestContext.Builder#child(String, Object) child}
  - {@link oaj.rest.RestContext.Builder#children(Object...) children}
  - {@link oaj.rest.RestContext.Builder#config(Config) config}
  - {@link oaj.rest.RestContext.Builder#consumes(MediaType...) consumes}
  - {@link oaj.rest.RestContext.Builder#debugDefault(Enablement) debugDefault}
  - {@link oaj.rest.RestContext.Builder#defaultAccept(String) defaultAccept}
  - {@link oaj.rest.RestContext.Builder#defaultCharset(Charset) defaultCharset}
  - {@link oaj.rest.RestContext.Builder#defaultClasses(Class...) defaultClasses}
  - {@link oaj.rest.RestContext.Builder#defaultContentType(String) defaultContentType}
  - {@link oaj.rest.RestContext.Builder#defaultRequestAttributes(NamedAttribute...) defaultRequestAttributes}
  - {@link oaj.rest.RestContext.Builder#defaultRequestHeaders(Header...) defaultRequestHeaders}
  - {@link oaj.rest.RestContext.Builder#defaultResponseHeaders(Header...) defaultResponseHeaders}
  - {@link oaj.rest.RestContext.Builder#defaultSetting(String, Object) defaultSetting}
  - {@link oaj.rest.RestContext.Builder#disableContentParam(boolean) disableContentParam}
  - {@link oaj.rest.RestContext.Builder#logger(Logger) logger}
  - {@link oaj.rest.RestContext.Builder#maxInput(String) maxInput}
  - {@link oaj.rest.RestContext.Builder#path(String) path}
  - {@link oaj.rest.RestContext.Builder#parserListener(Class) parserListener}
  - {@link oaj.rest.RestContext.Builder#produces(MediaType...) produces}
  - {@link oaj.rest.RestContext.Builder#renderResponseStackTraces(boolean) renderResponseStackTraces}
  - {@link oaj.rest.RestContext.Builder#restOpArgs(Class...) restOpArgs}
  - {@link oaj.rest.RestContext.Builder#serializerListener(Class) serializerListener}
  - {@link oaj.rest.RestContext.Builder#swaggerProvider(Class) swaggerProvider}
  - {@link oaj.rest.RestContext.Builder#uriAuthority(String) uriAuthority}
  - {@link oaj.rest.RestContext.Builder#uriContext(String) uriContext}
  - {@link oaj.rest.RestContext.Builder#uriRelativity(UriRelativity) uriRelativity}
  - {@link oaj.rest.RestContext.Builder#uriResolution(UriResolution) uriResolution}

For more complex configurations, access to sub-builders is provided via the following methods:

- {@link oaj.rest.RestContext.Builder}
  - {@link oaj.rest.RestContext.Builder#callLogger() callLogger}
  - {@link oaj.rest.RestContext.Builder#config() config}
  - {@link oaj.rest.RestContext.Builder#consumes() consumes}
  - {@link oaj.rest.RestContext.Builder#debugEnablement() debugEnablement}
  - {@link oaj.rest.RestContext.Builder#defaultClasses() defaultClasses}
  - {@link oaj.rest.RestContext.Builder#defaultRequestAttributes() defaultRequestAttributes}
  - {@link oaj.rest.RestContext.Builder#defaultRequestHeaders() defaultRequestHeaders}
  - {@link oaj.rest.RestContext.Builder#defaultResponseHeaders() defaultResponseHeaders}
  - {@link oaj.rest.RestContext.Builder#defaultSettings() defaultSettings}
  - {@link oaj.rest.RestContext.Builder#encoders() encoders}
  - {@link oaj.rest.RestContext.Builder#jsonSchemaGenerator() jsonSchemaGenerator}
  - {@link oaj.rest.RestContext.Builder#logger() logger}
  - {@link oaj.rest.RestContext.Builder#messages() messages}
  - {@link oaj.rest.RestContext.Builder#methodExecStore() methodExecStore}
  - {@link oaj.rest.RestContext.Builder#parsers() parsers}
  - {@link oaj.rest.RestContext.Builder#partParser() partParser}
  - {@link oaj.rest.RestContext.Builder#partSerializer() partSerializer}
  - {@link oaj.rest.RestContext.Builder#produces() produces}
  - {@link oaj.rest.RestContext.Builder#responseProcessors() responseProcessors}
  - {@link oaj.rest.RestContext.Builder#restOpArgs() restOpArgs}
  - {@link oaj.rest.RestContext.Builder#rootBeanStore() rootBeanStore}
  - {@link oaj.rest.RestContext.Builder#serializers() serializers}
  - {@link oaj.rest.RestContext.Builder#staticFiles() staticFiles}
  - {@link oaj.rest.RestContext.Builder#swaggerProvider() swaggerProvider}
  - {@link oaj.rest.RestContext.Builder#thrownStore() thrownStore}
  - {@link oaj.rest.RestContext.Builder#varResolver() varResolver}

- The builders or built objects above can also be defined as injected beans defined in a Spring Configuration if you wish to do all your app configuration Spring-style. This is described in detail in the juneau-rest-server-springboot documentation.

The programmatic equivalent to the annotated lifecycle methods are below:

- {@link oaj.rest.RestContext.Builder}
  - {@link oaj.rest.RestContext.Builder#postInitMethods() postInitMethods}
  - {@link oaj.rest.RestContext.Builder#postInitChildFirstMethods() postInitChildFirstMethods}
  - {@link oaj.rest.RestContext.Builder#startCallMethods() startCallMethods}
  - {@link oaj.rest.RestContext.Builder#preCallMethods() preCallMethods}
  - {@link oaj.rest.RestContext.Builder#postCallMethods() postCallMethods}
  - {@link oaj.rest.RestContext.Builder#endCallMethods() endCallMethods}
  - {@link oaj.rest.RestContext.Builder#destroyMethods() destroyMethods}

- It is also possible to override methods on the {@link oajr.RestContext} class itself by providing your own specialized subclass via the {@link oaj.rest.RestContext.Builder#type(Class)} method.