HTTP API Toolkit HTTP API Toolkit
HTTP API Toolkit HTTP API Toolkit
DocFX + Singulink = ♥

Search Results for

    Method SetApiRejectionResponse

    SetApiRejectionResponse(RateLimiterOptions, string?)

    Configures rejected requests to receive a TooManyRequestsApiException response in the toolkit's error format, with the RateLimited error code, so that clients built with the toolkit report it like any other API error. A request that a per-client limit with a RejectionMessage rejects receives that message. RetryAfter is set when the limiter reports how long the client should wait, which for the per-client limits is the time until the next window starts. A request that a per-client limit could not count because the short-lived store threw a ServiceUnavailableApiException, such as a full MemoryShortLivedStore, receives that exception instead.

    Declaration
    public static RateLimiterOptions SetApiRejectionResponse(this RateLimiterOptions options, string? message = null)
    Parameters
    Type Name Description
    RateLimiterOptions options

    The rate limiter options.

    string message

    The message reported to the client for the limits without a message of their own, or null to use a default message.

    Returns
    Type Description
    RateLimiterOptions
    Remarks

    This replaces OnRejected and sets RejectionStatusCode.

    SetApiRejectionResponse(RateLimiterOptions, Func<RateLimitRejectionContext, string>)

    Configures rejected requests to receive a TooManyRequestsApiException response in the toolkit's error format, as SetApiRejectionResponse(RateLimiterOptions, string?) does, with the message that a function returns for each rejected request.

    Declaration
    public static RateLimiterOptions SetApiRejectionResponse(this RateLimiterOptions options, Func<RateLimitRejectionContext, string> getMessage)
    Parameters
    Type Name Description
    RateLimiterOptions options

    The rate limiter options.

    Func<RateLimitRejectionContext, string> getMessage

    A function that returns the message reported to the client, given the details of the rejected request: its context, the RejectionMessage of the per-client limit that rejected it, and how long the client should wait.

    Returns
    Type Description
    RateLimiterOptions
    Remarks
    This replaces OnRejected and sets RejectionStatusCode.
    © Singulink. All rights reserved.