Skip to content
forked from rfoel/strava

JavaScript wrapper for the Strava JSON API

License

Notifications You must be signed in to change notification settings

launchport/strava

 
 

Repository files navigation

Strava

npm npm bundle size NPM semantic-release

This library is a fully typed JavaScript wrapper of the Strava JSON API.

Installation

To install the package, run:

npm install strava

or

yarn add strava

Usage

The way the library is implemented the user must have gone through the Strava OAuth flow beforehand and got a refresh token. This way we can ensure that whenever needed we get a new access token.

This may not be the best way to work with the API and I'm open to suggestions to make it better.

import { Strava } from 'strava'

const strava = new Strava({
  client_id: '123',
  client_secret: 'abc',
  refresh_token: 'def',
})

;(async () => {
  try {
    const activities = await strava.activities.getLoggedInAthleteActivities()
    console.log(activities)
  } catch (error) {
    console.log(error)
  }
})()

Refreshing the access token

This library will automatically refresh the access token when needed. You may need to store the refresh token somewhere, so you can use it on_token_refresh callback.

import { Strava } from 'strava'

const strava = new Strava({
  client_id: '123',
  client_secret: 'abc',
  refresh_token: 'def',
  on_token_refresh: (response: RefreshTokenResponse) => {
    db.set('refresh_token', response.refresh_token)
  }
})

Contributing

Issues and pull requests are welcome.

License

MIT

About

JavaScript wrapper for the Strava JSON API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%