This project is a simple Kotlin HTTP4K backend designed to manage the Wahoo Cloud API OAuth flow and enable users to obtain an API token. It utilizes environment variables for self-configuration of API credentials and includes functionality to create a Dockerfile for easy deployment with fly.io. Additionally, an example config file for fly.io has been included.
Before running this project, ensure that you have the following prerequisites installed:
- Kotlin
- HTTP4K
- Docker (optional)
- fly.io CLI (optional)
To install and run the project locally, follow these steps:
-
Clone the repository:
git clone https://github.com/james-millner/kotlin-wahoo-cloud-api.git
-
Navigate to the project directory:
cd kotlin-wahoo-cloud-api
-
Set up the required environment variables. You can do this by creating a
.env
file in the root directory of the project and populating it with the necessary values. The required environment variables are:CLIENT_ID
: The Wahoo Cloud API client ID.CLIENT_SECRET
: The Wahoo Cloud API client secret.REDIRECT_URI
: The redirect URI for the OAuth flow.
-
Build and run the project:
./gradlew run
This command will compile and run the project, making it accessible at
http://localhost:8080
.
Once the project is running, you can use an HTTP client (e.g., cURL or Postman) to interact with the API endpoints. Here are some example requests:
- GET /authorize: Retrieves the API token using the OAuth flow.
To deploy the project using Docker, follow these steps:
-
Ensure that Docker is installed and running on your machine.
-
Build the Docker image:
docker build -t your-image-name .
-
Run the Docker container:
docker run -p 8080:8080 your-image-name
The project will be accessible at
http://localhost:8080
. -
Hit the
/authorize
endpoint to retrieve the API token.
To deploy the project using fly.io, follow these steps:
-
Install the fly.io CLI by following the instructions provided in the official documentation.
-
Log in to fly.io using the CLI:
flyctl auth login
-
Initialize a new fly.io app:
flyctl init
-
Update the generated
fly.toml
file with your desired configuration. You can use the includedfly.toml
file as a reference. -
Deploy the app to fly.io:
flyctl deploy
Follow the prompts to deploy your application.
For more information on deploying with fly.io, refer to their official documentation.
Contributions are welcome! If you find any issues or have suggestions for improvements, please submit an issue or a pull request to the repository.