Events
CustomEvents dispatched by <rapi-doc>. Listen with addEventListener; the payload is in event.detail. How to use them is in React to Events.
const doc = document.querySelector('rapi-doc');
// Before a Try request is sent: add a headerdoc.addEventListener('before-try', (e) => { e.detail.request.headers.append('X-Tenant-ID', 'acme');});
// The reader picked another serverdoc.addEventListener('api-server-change', (e) => { console.log('Server:', e.detail.selectedServer);});Nothing on this page matches.
| Event | Description |
|---|---|
before-render | Dispatched before rendering starts. Provides the parsed OpenAPI
specification object via e.detail.spec, allowing programmatic
modifications before the UI tree is built. |
spec-loaded | Dispatched after the OpenAPI specification has been fully fetched, parsed,
resolved, and rendered into the DOM. Provides the resolved spec object in e.detail. |
nav-active-change | Dispatched when the active section changes: a click in the sidebar,
scrollToPath, a hash change, or scrolling that brings a
different section into view. Bubbles and is composed, so a page-level listener outside the
shadow DOM receives it. The detail is the same from every source: e.detail.elementId is the section's element id, e.detail.type is operation, tag or section (the overview, servers,
authentication, a description heading, a component), and e.detail.operationId is the operation's operationId from the spec, present only for an operation that has one. Static
sidebars rendered with @rapidoc/prerender and bindNavBar use it to highlight the current item. |
before-try | Dispatched when a user clicks "TRY" before the network request is initiated.
Provides a mutable Request-like object via e.detail.request to append headers, rewrite parameters, or modify payloads, along
with an AbortController via e.detail.controller to abort requests conditionally. Example: Append custom authorization headers before sending:
Example: Append query parameters to all GET requests:
Example: Abort specific requests conditionally:
|
after-try | Dispatched after a try request completes. Provides e.detail.request and e.detail.response. In the
event of a network or protocol error, provides request and error objects. |
request-aborted | Dispatched when an in-flight API try request is aborted by the user or
programmatically via AbortController. |
api-server-change | Dispatched when the active target API server is modified in the
dropdown. |
before-authorize | Dispatched immediately before opening the OAuth authorization popup
window. Provides e.detail.securitySchemeId, e.detail.flowType, e.detail.authUrl, and mutable
e.detail.authParams (URLSearchParams). Calling e.preventDefault()
cancels opening the authorization window. Example: Dynamically inject a launch token or proxy parameter: |
before-token-request | Dispatched immediately before sending the POST request to the
OAuth2 token endpoint. Provides e.detail.securitySchemeId, e.detail.grantType, e.detail.tokenUrl, mutable e.detail.params (URLSearchParams), e.detail.headers (Headers), and mutable e.detail.request.
Calling e.preventDefault() cancels the token request. Example: Add a custom token audience or header: |