I developed a program that integrates with the Strava API to retrieve and display total distance for the current year. By connecting to your Strava account, it fetches the necessary data and outputs the total distance for different sports, providing an easy way to track annual progress. I created this project as a way to learn and explore the Clojure programming language.
- Retrieve total distance for current year
- Support for multiple sports (run, ride)
- RESTful API with JSON responses
- Authentication via refresh token
-
Clone the repository:
git clone https://github.com/skvggor/strava-api-wrapper-clojure.git cd strava-api-wrapper-clojure -
Create a
config.ednfile based onconfig.edn.example:{:strava-domain "https://www.strava.com" :strava-api-url "/api/v3" :strava-client-id "YOUR_CLIENT_ID" :strava-client-secret "YOUR_CLIENT_SECRET" :strava-refresh-token "YOUR_REFRESH_TOKEN" :strava-user-id "YOUR_USER_ID" :port 3000} -
Install dependencies:
lein deps
Start the server:
bash start.shOr manually:
lein runThe server will start on port 3000 (or the port specified in config.edn).
For production deployment with Docker and Caddy reverse proxy, create a compose.yml file:
services:
strava-api:
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
networks:
- caddy_net
labels:
- caddy=your-subdomain.yourdomain.com
- caddy.reverse_proxy={{upstreams 3002}}
- caddy.encode=zstd gzip
expose:
- 3002
volumes:
- ./config.edn:/usr/src/app/config.edn
networks:
caddy_net:
external: trueReplace your-subdomain.yourdomain.com with your actual domain. Ensure your config.edn file is present and properly configured.
Retrieve total distance for the current year.
Endpoint: GET /api/v1/strava/total-distance/current-year
Query Parameters:
sport(optional): Sport type. Supported values:run(default),ride
Examples:
# Get running distance (default)
curl http://localhost:3000/api/v1/strava/total-distance/current-year
# Get running distance
curl http://localhost:3000/api/v1/strava/total-distance/current-year?sport=run
# Get cycling distance
curl http://localhost:3000/api/v1/strava/total-distance/current-year?sport=rideResponse:
{
"distance": 123.4
}lein teststrava-api-wrapper-clojure/
├── src/
│ └── strava_api/
│ ├── core.clj # Main application and server setup
│ ├── handlers.clj # HTTP request handlers
│ ├── strava.clj # Strava API integration
│ └── utils.clj # Utility functions
├── test/
│ └── strava_api/
│ └── utils_test.clj # Unit tests
├── config.edn # Configuration file (not tracked)
├── config.edn.example # Example configuration
└── start.sh # Script to start the server
- Clojure 1.12.4 - Functional programming language
- Compojure - Routing library
- http-kit - HTTP server
- clj-http - HTTP client
- cheshire - JSON parsing
This project is licensed under the Eclipse Public License - v 2.0.