@iracing-data/api
TypeScript icon, indicating that this package has built-in type declarations

0.0.2-alpha.1 • Public • Published

@iracing-data/api

An implementation for the iRacing /data API. Written in TypeScript, powered by Axios.

Installation

Coming Soon

Usage

Coming Soon

Contributing

Adding new API endpoints

docs

Adding implementation to the client

Add the new route to the client, defined in the src/ root:

export class IRacingAPIClient {
  // ... existing implementation

  // Add the new route for easy access for consumers
  async newResourceEndpoint() {
    // Execute the network request
    const response = await this.api.data.new.resourceEndpoint();

    // !!!: Error handling if appropriate
    // In most cases, this is irrelevant, but if you want to provide
    // some context to the error, you can do so here.
    if (response.status !== 200) {
      throw new Error(`Failed to fetch data: ${response.status}`);
    }

    // Use the helper function the fetch the JSON from the provided link
    return fetchValidLinkData(response.data);
  }

  // Or, if your endpoint takes parameters...
  async newResourceEndpointWithParameters(
    input: Parameters<IRacingAPI['data']['new']['resourceEndpoint']>[0] // Typescript annotation to forward the parameters from the function definition
  ) {
    const response = await this.api.data.new.resourceEndpoint(input);

    // ...same as above
  }

}

Readme

Keywords

none

Package Sidebar

Install

npm i @iracing-data/api

Weekly Downloads

15

Version

0.0.2-alpha.1

License

none

Unpacked Size

140 kB

Total Files

95

Last publish

Collaborators

  • justinmakaila