A Self-Service Adapter is a custom integration layer that connects SIR Widgets to your betting data sources. Instead of using Sportradar's hosted adapter, you implement the data fetching logic yourself, giving you complete control over:
Data Sources – Connect to any odds/betting API
Data Transformation – Map your API responses to the widget-expected format
Caching Strategy – Implement your own caching and optimization
Real-Time Updates – Control how and when data refreshes
Understand the Adapter Structure
The adapter object consists of two primary properties:
config: Contains static configuration for widgets, such as layout options and filtering rules.
endpoints: A collection of functions that the widget calls to request data (e.g., event details, markets, odds).
constadapter={config:{widget:{'betRecommendation.eventList':{layout:{/* EventListMarketsConfig */},allowedMarkets:{/* SportMarketsMap */}}, // ... other widgets}},endpoints:{event:(args,callback)=>{ // Fetch and return event data // Return optional unsubscribe function},eventMarkets:(args,callback)=>{ // Fetch and return markets for event},market:(args,callback)=>{ // Fetch and return specific market} // ... other endpoints}};
The following diagram illustrates how data flows from your backend API through the adapter and into the widget.
The adapter acts as a bridge, ensuring that whatever format your API returns is converted into the structure the widget expects.
Workflow Breakdown
The widget starts by asking the adapter which markets are available for each event using the availableMarketsForEvent endpoint. Example: The widget requests available markets for Event A, Event B, and Event C.
The adapter responds to each request with the available markets for that event. Example: For Event A, the adapter returns "1x2" and "Spread" markets. For Event B, only "1x2" is available. For Event C, no data is returned (e.g., event expired). The widget displays placeholders while it loads detailed data.
Data Retrieval Phase: The widget now requests all the data it needs in parallel. It calls the market endpoint for odds and outcomes, the event endpoint for event details (like team names and scores), and the betSlipSelection endpoint to check the user's current selections. Example: For Event A, the widget requests both "1x2" and "Spread" markets. For Event B, it requests "1x2". It also fetches event details for both events and checks the user's bet slip selections.
When the widget receives data from the event endpoint, it fills in the placeholders with event information. Example: Team names, scores, match period, and start time are displayed.
When the widget receives data from the market endpoint, it fills in the odds and outcomes for each market. Example: The widget displays the latest odds for each outcome.
When the widget receives data from the betSlipSelection endpoint, it updates the UI to reflect the user's current selections. Example: If the user has already selected outcome 1 for the "1x2" market in Event A, the widget marks it as selected.
Once all endpoint requests have returned data (or timed out), the widget displays the complete information to the user.
The sequence above is a general example. Each widget has its own unique data pattern, which is detailed in its specific documentation.
Base Implementation Example
Start with this basic HTML structure to implement your self-service adapter.
Adapter Implementation
The adapter is a JavaScript object that serves as the interface between your application's data layer and the SIR Widgets. It defines how widgets request data and how your application provides it.
Implementing the Adapter Endpoints
Now implement the complete adapter with all core endpoints. Here's the full adapter implementation with mock data:
Example: Mocked Data Adapter
Here's the complete HTML file with all pieces assembled:
Code Block
Connect to Your API
To connect to your actual betting API, you need to replace the mock data with actual network requests. This typically involves fetching data from your backend and transforming it to match the structure expected by the widget.
Adding Real-Time Updates
For live events, it is crucial to keep odds and market status up to date. You can achieve this using polling or WebSockets. Here is an example using polling:
sequenceDiagram
participant Widget
participant Adapter
participant UserAPI as Your Backend API
Widget->>Adapter: 1. Request Data (e.g. eventMarkets)
Adapter->>UserAPI: 2. Fetch or Subscribe to Data (HTTP/WebSocket)
UserAPI-->>Adapter: 3. Return Raw Data (JSON)
Adapter->>Adapter: 4. Transform to SIR Format
Adapter-->>Widget: 5. Return Data via Callback
Adapter-->>Widget: 6. On new data return it via Callback