-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbasic-usage.js
More file actions
39 lines (32 loc) · 1.1 KB
/
basic-usage.js
File metadata and controls
39 lines (32 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Basic usage example - JavaScript (ESM)
*/
import { OddsAPIClient } from 'odds-api-io';
const client = new OddsAPIClient({
apiKey: process.env.ODDS_API_KEY || 'your-api-key-here',
});
try {
// Get all available sports
console.log('Fetching sports...');
const sports = await client.getSports();
console.log(`Found ${sports.length} sports`);
sports.slice(0, 5).forEach(s => console.log(` - ${s.name} (${s.slug})`));
// Get upcoming NBA events
console.log('\nFetching NBA events...');
const events = await client.getEvents({
sport: 'basketball',
league: 'usa-nba',
});
console.log(`Found ${events.length} NBA events`);
if (events.length > 0) {
const event = events[0];
console.log(`\nFirst event: ${event.home} vs ${event.away}`);
console.log(` ID: ${event.id} | Date: ${event.date} | Status: ${event.status}`);
}
// Search for Lakers games
console.log('\nSearching for Lakers games...');
const lakersGames = await client.searchEvents('Lakers');
console.log(`Found ${lakersGames.length} Lakers games`);
} catch (error) {
console.error('Error:', error);
}