Package discord4j.rest
Class RestClientBuilder<C,O extends RouterOptions>
java.lang.Object
discord4j.rest.RestClientBuilder<C,O>
Builder suited for creating a
RestClient. To acquire an instance, see createRest(String).-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AllowedMentionsprotected final Function<RestClientBuilder.Config,C> protected ExchangeStrategiesprotected GlobalRateLimiterprotected JacksonResourcesprotected final Function<RouterOptions,O> protected ReactorResourcesprotected RequestQueueFactoryprotected List<ResponseFunction>protected String -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedRestClientBuilder(RestClientBuilder<?, ?> source, Function<RestClientBuilder.Config, C> clientFactory, Function<RouterOptions, O> optionsModifier) protectedRestClientBuilder(String token, Function<RestClientBuilder.Config, C> clientFactory, Function<RouterOptions, O> optionsModifier) -
Method Summary
Modifier and TypeMethodDescriptionbuild()Create a client capable of connecting to Discord REST API using aDefaultRouterthat is capable of working in monolithic environments.Create a client capable of connecting to Discord REST API using a customRouterfactory.static RestClientBuilder<RestClient,RouterOptions> createRest(String token) Initialize a new builder with the given token.static RestClientBuilder<RestClient,RouterOptions> onClientResponse(ResponseFunction responseFunction) Sets a new API response behavior to the supportingRouter, allowing cross-cutting behavior across all requests made by it.setDefaultAllowedMentions(AllowedMentions allowedMentions) Sets theAllowedMentionsobject that can limit the mentioned target entities that are notified upon message created by this client.setExchangeStrategies(ExchangeStrategies exchangeStrategies) Set the strategies to use when reading or writing HTTP request and response body entities.<O2 extends RouterOptions>
RestClientBuilder<C,O2> setExtraOptions(Function<? super O, O2> optionsModifier) Add a configuration forRouterimplementation-specific cases, changing the type of the currentRouterOptionsobject passed to theRouterfactory in build methods.setGlobalRateLimiter(GlobalRateLimiter globalRateLimiter) Define theGlobalRateLimiterto be applied while configuring theRouterfor a client.setJacksonResources(JacksonResources jacksonResources) Set a newJacksonResourcesto this builder, dedicated to provide anObjectMapperfor serialization and deserialization of data.setReactorResources(ReactorResources reactorResources) Set a newReactorResourcesdedicated to set up a connection pool, an event pool, as well as the supportingHttpClientused for making rest requests and maintaining gateway connections.setRequestQueueFactory(RequestQueueFactory requestQueueFactory) Sets theRequestQueueFactorythat will provideRequestQueueinstances for the router.Change the token stored in this builder.
-
Field Details
-
clientFactory
-
optionsModifier
-
token
-
reactorResources
-
jacksonResources
-
exchangeStrategies
-
responseTransformers
-
globalRateLimiter
-
requestQueueFactory
-
allowedMentions
-
-
Constructor Details
-
RestClientBuilder
protected RestClientBuilder(String token, Function<RestClientBuilder.Config, C> clientFactory, Function<RouterOptions, O> optionsModifier) -
RestClientBuilder
protected RestClientBuilder(RestClientBuilder<?, ?> source, Function<RestClientBuilder.Config, C> clientFactory, Function<RouterOptions, O> optionsModifier)
-
-
Method Details
-
createRest
Initialize a new builder with the given token.- Parameters:
token- the bot token used to authenticate to Discord
-
createRestApplication
-
setExtraOptions
public <O2 extends RouterOptions> RestClientBuilder<C,O2> setExtraOptions(Function<? super O, O2> optionsModifier) Add a configuration forRouterimplementation-specific cases, changing the type of the currentRouterOptionsobject passed to theRouterfactory in build methods.- Type Parameters:
O2- new type for the options- Parameters:
optionsModifier-Functionto transform theRouterOptionstype to provide customRouterimplementations a proper configuration object.- Returns:
- a new
RestClientBuilderthat will now work with the new options type.
-
setToken
Change the token stored in this builder.- Parameters:
token- the new bot token- Returns:
- this builder
-
setReactorResources
Set a newReactorResourcesdedicated to set up a connection pool, an event pool, as well as the supportingHttpClientused for making rest requests and maintaining gateway connections.- Parameters:
reactorResources- the new resource provider used for rest and gateway operations- Returns:
- this builder
-
setJacksonResources
Set a newJacksonResourcesto this builder, dedicated to provide anObjectMapperfor serialization and deserialization of data.- Parameters:
jacksonResources- the new resource provider for serialization and deserialization- Returns:
- this builder
-
setExchangeStrategies
Set the strategies to use when reading or writing HTTP request and response body entities. Defaults to usingsetJacksonResources(JacksonResources)to build aExchangeStrategies.jackson(ObjectMapper)that is capable of encoding and decoding JSON using Jackson.- Parameters:
exchangeStrategies- the HTTP exchange strategies to use- Returns:
- this builder
-
onClientResponse
Sets a new API response behavior to the supportingRouter, allowing cross-cutting behavior across all requests made by it.The given
ResponseFunctionwill be applied after every response. Calling this function multiple times will result in additive behavior, so care must be taken regarding the order in which multiple calls occur. Transformations will be added to the response pipeline in that order.Built-in factories are supplied for commonly used behavior:
ResponseFunction.emptyIfNotFound()transforms any HTTP 404 error into an empty sequence.ResponseFunction.emptyIfNotFound(RouteMatcher)transforms HTTP 404 errors from the givenRoutes into an empty sequence.ResponseFunction.emptyOnErrorStatus(RouteMatcher, Integer...)provides the same behavior as above but for any given status codes.ResponseFunction.retryOnceOnErrorStatus(Integer...)retries once for the given status codes.ResponseFunction.retryOnceOnErrorStatus(RouteMatcher, Integer...)provides the same behavior as above but for any matchingRoute.
- Parameters:
responseFunction- theResponseFunctionto transform the responses from matching requests.- Returns:
- this builder
-
setGlobalRateLimiter
Define theGlobalRateLimiterto be applied while configuring theRouterfor a client.GlobalRateLimiterpurpose is to coordinate API requests to properly delay them under global rate limiting scenarios. A supportingRouterfactory (supplied atbuild(Function)) is responsible for applying the given limiter.- Parameters:
globalRateLimiter- the limiter instance to be used while configuring aRouter- Returns:
- this builder
- See Also:
-
setRequestQueueFactory
Sets theRequestQueueFactorythat will provideRequestQueueinstances for the router.If not set, it will use a
RequestQueueFactoryproviding request queues backed by a sink with reasonable buffering capacity, delaying overflowing requests.- Parameters:
requestQueueFactory- the factory that will provideRequestQueueinstances for the router- Returns:
- this builder
- See Also:
-
setDefaultAllowedMentions
Sets theAllowedMentionsobject that can limit the mentioned target entities that are notified upon message created by this client.- Parameters:
allowedMentions- the options for limiting message mentions. SeeAllowedMentions.builder().- Returns:
- this builder
-
build
Create a client capable of connecting to Discord REST API using aDefaultRouterthat is capable of working in monolithic environments.- Returns:
- a configured
RestClientbased on this builder parameters
-
build
Create a client capable of connecting to Discord REST API using a customRouterfactory. The resultingRestClientwill use the producedRouterfor every request.- Parameters:
routerFactory- the factory ofRouterimplementation- Returns:
- a configured
RestClientbased on this builder parameters
-