How to Build a Workout App
Using a REST API
A complete guide to integrating the WorkoutX exercise database API into your fitness application. Covers authentication, fetching exercises, playing exercise animations, and filtering by muscle group — with real code examples in JavaScript and Python.
verified Published by the WorkoutX team — builders of the exercise API used by fitness app developers. Learn more
A step-by-step programming tutorial for building a modern workout app. Includes complete boilerplate examples in JavaScript and Python for fetching exercises, playing MP4 exercise animations, and handling client-side filtering.
What You'll Build
By the end of this guide, your app will be able to: fetch a list of exercises from a REST API, filter them by body part or target muscle, play an animated preview for each exercise, and handle pagination for large result sets. We'll use the WorkoutX API v2 — an exercise database with 1,900+ exercises and 720p video animations, free to start, covering everything from a basic push-up to a heavy barbell deadlift.
Prerequisites: Basic knowledge of HTTP requests and JSON. No specific framework required — examples work in vanilla JavaScript, Node.js, Python, or any language that can make HTTP requests.
Step 1: Get Your API Key
Every request to the WorkoutX API requires an API key in the X-WorkoutX-Key header. The free plan gives you 500 requests in total (one-time) with no credit card required — enough to prototype and build your MVP. Free plan responses return up to 10 exercises per request, with watermarked video previews.
- Go to workoutxapp.com/dashboard and create a free account
- Your API key appears instantly in the Developer Portal
- Format:
wx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Step 2: Make Your First Request
The base URL for all API calls is https://api.workoutxapp.com/v2. Pass your key in the X-WorkoutX-Key header (v2 rejects keys in the URL). Here's a minimal example that fetches 5 exercises:
const API_KEY = 'wx_your_key_here'; const BASE_URL = 'https://api.workoutxapp.com/v2'; async function fetchExercises() { const response = await fetch(`${BASE_URL}/exercises?limit=5`, { headers: { 'X-WorkoutX-Key': API_KEY } }); if (!response.ok) { throw new Error(`API error: ${response.status}`); } const { total, results } = await response.json(); // results is an array of exercise objects; total counts all matches console.log(total, results); return results; } fetchExercises();
import requests API_KEY = 'wx_your_key_here' BASE_URL = 'https://api.workoutxapp.com/v2' def fetch_exercises(limit=5): response = requests.get( f'{BASE_URL}/exercises', headers={'X-WorkoutX-Key': API_KEY}, params={'limit': limit} ) response.raise_for_status() return response.json()['results'] exercises = fetch_exercises() for ex in exercises: print(f"{ex['name']} — {ex['bodyPart']}")
Understanding the Response Shape
Each exercise object contains the following fields:
{
"id": "ex_WOZL6H",
"name": "Push Ups Bodyweight",
"model": "male",
"counterpartId": "ex_KK4RJV",
"bodyPart": "Chest",
"target": "Pectorals",
"equipment": "Body Weight",
"difficulty": "intermediate",
"caloriesPerMinute": 6.1,
"instructions": [
"Begin in a plank position...",
"Lower your body towards the floor..."
],
"tips": ["Keep your core engaged..."],
"legacyIds": ["0662"],
"media": {
"expiresAt": "...",
"mp4": "https://…/m/v1/ex_WOZL6H/mp4-720.mp4?…",
"poster": "https://…/m/v1/ex_WOZL6H/poster.jpg?…"
}
}
List endpoints wrap these objects in { total, limit, offset, results }. The media links are signed and expire after 24–25 hours, so store the exercise id in your database, never the URLs, and read fresh links from the response when you show an exercise.
Step 3: Filter by Body Part
The most common use case is letting users pick a body part (chest, back, shoulders, etc.) and see relevant exercises. Add the bodyPart query parameter to /exercises:
async function getExercisesByBodyPart(bodyPart) { // Valid: chest, back, waist, shoulders, upper arms, // lower arms, upper legs, lower legs, cardio, neck const url = `${BASE_URL}/exercises?bodyPart=${encodeURIComponent(bodyPart)}&limit=10`; const res = await fetch(url, { headers: { 'X-WorkoutX-Key': API_KEY } }); const { results } = await res.json(); return results; } // Example: get 10 chest exercises const chestExercises = await getExercisesByBodyPart('chest');
Step 4: Display Exercise Animations
Each exercise has a media object with an mp4 animation (600×720, 30 fps, typically 100–300 KB) and a poster image. Play the video muted and looping, and show the poster while it loads. In long lists on mobile, show the poster first and start each video when its card scrolls into view:
function renderExerciseCard(exercise) { return ` <div class="exercise-card"> <video src="${exercise.media.mp4}" poster="${exercise.media.poster}" autoplay loop muted playsinline width="300" height="360" aria-label="${exercise.name} exercise animation" ></video> <div class="exercise-info"> <h3>${exercise.name}</h3> <span class="badge">${exercise.bodyPart}</span> <span class="badge">${exercise.target}</span> <span class="badge">${exercise.equipment}</span> <p class="effort">${exercise.difficulty} · ~${exercise.caloriesPerMinute} cal/min</p> </div> </div> `; } // Render all exercises const container = document.getElementById('exercises'); container.innerHTML = exercises.map(renderExerciseCard).join('');
Step 5: Filter by Target Muscle
For more granular control, filter by target muscle. This is useful when your users want to specifically target biceps (e.g., barbell curl), triceps, or quads:
async function getExercisesByTarget(target) { // Examples: abs, biceps, triceps, quads, glutes, // hamstrings, calves, delts, lats, pectorals const url = `${BASE_URL}/exercises?target=${encodeURIComponent(target)}&limit=10`; const res = await fetch(url, { headers: { 'X-WorkoutX-Key': API_KEY }}); const { results } = await res.json(); return results; } // Get available target muscles async function getTargetList() { const res = await fetch(`${BASE_URL}/targets`, { headers: { 'X-WorkoutX-Key': API_KEY } }); return res.json(); // Returns the 18 target muscles with exercise counts }
Step 6: Handle Pagination
The v2 library has 1,900+ exercises (2,700+ clips, since many come with both a male and a female model). Use limit and offset to paginate results, and the total field to know when you're done. limit is capped at 10 on Free, 100 on Starter and 200 on other plans. A "Load More" pattern works well for fitness apps:
let offset = 0; const PAGE_SIZE = 10; async function loadMore(bodyPart) { const url = `${BASE_URL}/exercises?bodyPart=${encodeURIComponent(bodyPart)}` + `&limit=${PAGE_SIZE}&offset=${offset}`; const res = await fetch(url, { headers: { 'X-WorkoutX-Key': API_KEY }}); const { total, results } = await res.json(); appendExercises(results); offset += results.length; // Hide the button once every result is loaded if (offset >= total) { document.getElementById('load-more').style.display = 'none'; } } // Initialize on page load loadMore('chest');
Step 7: Search Exercises by Name
Let users search for a specific exercise by name using the name query parameter on the main endpoint:
async function searchExercises(query) { const url = `${BASE_URL}/exercises?name=${encodeURIComponent(query)}`; const res = await fetch(url, { headers: { 'X-WorkoutX-Key': API_KEY }}); const { results } = await res.json(); return results; } // Debounce for search input let searchTimeout; document.getElementById('search').addEventListener('input', (e) => { clearTimeout(searchTimeout); searchTimeout = setTimeout(() => { searchExercises(e.target.value); }, 300); });
Error Handling Best Practices
Always handle the common API error codes your app may encounter:
async function apiRequest(endpoint) { try { const res = await fetch(`${BASE_URL}${endpoint}`, { headers: { 'X-WorkoutX-Key': API_KEY } }); switch (res.status) { case 200: return res.json(); case 400: throw new Error('Bad request — check query parameters'); case 401: throw new Error('Invalid API key'); case 429: throw new Error('Rate limit exceeded — upgrade your plan'); case 404: throw new Error('Exercise not found'); default: throw new Error(`API error ${res.status}`); } } catch (err) { console.error('WorkoutX API:', err.message); throw err; } }
Complete Minimal App
Here's a working single-file HTML app that ties everything together — a body part picker with exercise cards and looping exercise videos:
<!DOCTYPE html> <html lang="en"> <head> <title>My Workout App</title> <style> .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px,1fr)); gap: 16px; } .card { border: 1px solid #eee; border-radius: 8px; overflow: hidden; } .card video { width: 100%; height: 240px; object-fit: cover; } .card-body { padding: 12px; } .filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 24px; } button { padding: 8px 16px; border-radius: 6px; cursor: pointer; border: 1px solid #ddd; } button.active { background: #111; color: white; border-color: #111; } </style> </head> <body> <h1>Exercise Library</h1> <div class="filters" id="filters"></div> <div class="grid" id="exercises"></div> <script> const KEY = 'wx_your_key_here'; const BASE = 'https://api.workoutxapp.com/v2'; const PARTS = ['chest','back','shoulders','waist','upper arms','upper legs']; async function load(part) { const res = await fetch( `${BASE}/exercises?bodyPart=${encodeURIComponent(part)}&limit=10`, { headers: { 'X-WorkoutX-Key': KEY } } ); const { results } = await res.json(); document.getElementById('exercises').innerHTML = results.map(ex => ` <div class="card"> <video src="${ex.media.mp4}" poster="${ex.media.poster}" autoplay loop muted playsinline></video> <div class="card-body"> <h3>${ex.name}</h3> <p>${ex.target} · ${ex.equipment}</p> </div> </div> `).join(''); } // Render filter buttons document.getElementById('filters').innerHTML = PARTS.map(p => ` <button onclick="load('${p}')">${p}</button> `).join(''); load('chest'); // default </script> </body> </html>
Next Steps
You now have a working exercise browser. Here's where to go from here:
- Add workout builder: Let users save exercises into a "workout" and track sets/reps with localStorage
- Filter by equipment: Use
/exercises?equipment=dumbbellfor home vs. gym workouts, and combine it withbodyPartortargetin the same request - Offer the female model: Add
model=femaleto list female versions, or usecounterpartIdto switch an exercise between the male and female model - Translate: Add
lang=de(ortr,es,fr,zh-SG,zh-HK) for translated names, instructions and tips - Upgrade your plan: When you're ready to launch, the Starter plan gives you 5,000 requests/month and 720p media without a watermark for $19/month
Full API reference: See all available endpoints, parameters, and response schemas in the WorkoutX API Documentation.
Ready to start building?
Get your free API key in 30 seconds. 500 requests in total, no credit card required.