UNPKG

openf1-client

Version:

Library for querying data from the OpenF1 API

85 lines (60 loc) 1.99 kB
# OpenF1 Client A lightweight, zero-dependency TypeScript client for the [OpenF1 API](https://openf1.org/). ## Features - ✅ Written in TypeScript with full type support. - ✅ Zero-dependencies. - ✅ ES Module. - ✅ Simple and easy to use. ## Installation ```bash npm install openf1-client ``` ## Usage Here's a quick example of how to use the client to fetch session data: ```typescript import { OpenF1Client } from 'openf1-client' const client = new OpenF1Client() async function getSpanishGrandPrixSession() { try { const sessions = await client.getSessions({ meetingKey: 1229, // Spanish Grand Prix 2024 sessionName: 'Race' }) console.log(sessions) } catch (error) { console.error('Error fetching sessions:', error) } } getSpanishGrandPrixSession() ``` ## Client Options By default, the client returns data with `snake_case` keys, as provided by the OpenF1 API. You can enable automatic camelCase conversion during client initialization: ```typescript const client = new OpenF1Client({ camelize: true }) ``` If you would like additional info about the requests being made by the client, you can enable the debug option: ```typescript const client = new OpenF1Client({ debug: true }) ``` ## API The client provides methods for all supported OpenF1 API endpoints: - `getCarData(params)` - `getDrivers(params)` - `getIntervals(params)` - `getLaps(params)` - `getLocation(params)` - `getMeetings(params)` - `getPit(params)` - `getPosition(params)` - `getRaceControl(params)` - `getSessions(params)` - `getSessionResults(params)` (beta) - `getStartingGrid(params)` (beta) - `getStints(params)` - `getTeamRadio(params)` - `getWeather(params)` For detailed information on available query parameters for each endpoint, please refer to the official [OpenF1 API Documentation](https://openf1.org/#api-endpoints). ## Contributing Contributions are welcome! Please open an issue or submit a merge request. ## License [MIT](LICENSE)