Class ApiVersionConfigurer
java.lang.Object
org.springframework.web.reactive.config.ApiVersionConfigurer
Configure API versioning.
- Since:
- 7.0
- Author:
- Rossen Stoyanchev
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddSupportedVersions
(String... versions) Add to the list of supported versions to validate request versions against.protected @Nullable ApiVersionStrategy
setDefaultVersion
(@Nullable String defaultVersion) Configure a default version to assign to requests that don't specify one.setVersionParser
(@Nullable ApiVersionParser<?> versionParser) Configure a parser to parse API versions with.setVersionRequired
(boolean required) Whether requests are required to have an API version.usePathSegment
(int index) Add a resolver that extracts the API version from a path segment.useRequestHeader
(String headerName) Add a resolver that extracts the API version from a request header.useRequestParam
(String paramName) Add a resolver that extracts the API version from a request parameter.useVersionResolver
(ApiVersionResolver... resolvers) Add custom resolvers to resolve the API version.
-
Constructor Details
-
ApiVersionConfigurer
public ApiVersionConfigurer()
-
-
Method Details
-
useRequestHeader
Add a resolver that extracts the API version from a request header.- Parameters:
headerName
- the header name to check
-
useRequestParam
Add a resolver that extracts the API version from a request parameter.- Parameters:
paramName
- the parameter name to check
-
usePathSegment
Add a resolver that extracts the API version from a path segment.- Parameters:
index
- the index of the path segment to check; e.g. for URL's like "/{version}/..." use index 0, for "/api/{version}/..." index 1.
-
useVersionResolver
Add custom resolvers to resolve the API version.- Parameters:
resolvers
- the resolvers to use
-
setVersionParser
Configure a parser to parse API versions with.By default,
SemanticApiVersionParser
is used.- Parameters:
versionParser
- the parser to user
-
setVersionRequired
Whether requests are required to have an API version. When set totrue
,MissingApiVersionException
is raised, resulting in a 400 response if the request doesn't have an API version. When set to false, a request without a version is considered to accept any version.By default, this is set to
true
when API versioning is enabled by adding at least oneApiVersionResolver
). When adefaultVersion
is also set, this is automatically set tofalse
.- Parameters:
required
- whether an API version is required.
-
setDefaultVersion
Configure a default version to assign to requests that don't specify one.- Parameters:
defaultVersion
- the default version to use
-
addSupportedVersions
Add to the list of supported versions to validate request versions against. Request versions that are not supported result inInvalidApiVersionException
.Note that the set of supported versions is populated from versions listed in controller mappings. Therefore, typically you do not have to manage this list except for the initial API version, when controller don't have to have a version to start.
- Parameters:
versions
- supported versions to add
-
getApiVersionStrategy
-