datadog-ux-utils Documentation - v1.0.0
    Preparing search index...

    Class ApiRateGuard

    API rate guard for limiting requests per time window.

    // Limit to 5 requests per 2 seconds
    const guard = new ApiRateGuard({ windowMs: 2000, maxRequests: 5 });
    await guard.guardFetch('/api/patients');
    Index

    Constructors

    Methods

    Constructors

    Methods

    • Wrap a fetch call. If the guard blocks, it throws ApiRunawayBlockedError (or queues/drops according to strategy).

      Parameters

      • input: RequestInfo | URL
      • Optionalinit: RequestInit

      Returns Promise<Response>

    • Generic guard for arbitrary async API calls (Axios, graphql-request, etc.) Usage: await apiGuard.guard('POST /api/items', () => axios.post(...));

      Type Parameters

      • T

      Parameters

      • key: string
      • call: () => Promise<T>

      Returns Promise<undefined | T>

    • Clear counters for testing or when navigating away.

      Parameters

      • Optionalkey: string

      Returns void