Skip to main content

Overview

The exercise types define the structure for exercise data, including individual exercises and paginated responses. These types ensure type safety when working with exercise data throughout your application.

IExercise

Represents a single exercise with all its properties.
types.d.ts
interface IExercise {
  name: string;
  title: string;
  target: string;
  muscles_worked: string;
  bodyPart: string;
  equipment: string;
  id: string;
  id_: string;
  blog: string;
  images: string[];
  gifUrl: string;
  videos: string[];
  keywords: string[];
}

Properties

name
string
required
Unique identifier name for the exercise (usually lowercase with hyphens)
title
string
required
Display title of the exercise for user interfaces
target
string
required
Primary target muscle or muscle group
muscles_worked
string
required
Comma-separated list of all muscles engaged during the exercise
bodyPart
string
required
Body part category (e.g., “chest”, “back”, “legs”)
equipment
string
required
Required equipment for the exercise (e.g., “barbell”, “bodyweight”)
id
string
required
Primary identifier for the exercise
id_
string
required
Alternative identifier for the exercise
blog
string
required
URL or path to related blog content or detailed instructions
images
string[]
required
Array of image URLs showing exercise form and technique
gifUrl
string
required
Animated GIF URL demonstrating the exercise movement
videos
string[]
required
Array of video URLs with exercise tutorials and demonstrations
keywords
string[]
required
Search keywords and tags for exercise discovery

IExerciseData

Paginated response containing multiple exercises.
types.d.ts
interface IExerciseData {
  totalExercises: number;
  totalPages: number;
  data: IExercise[];
}

Properties

totalExercises
number
required
Total count of exercises matching the query
totalPages
number
required
Total number of pages available for pagination
data
IExercise[]
required
Array of exercise objects for the current page

IExerciseResponse

Wrapper for a single exercise response.
types.d.ts
interface IExerciseResponse {
  data: IExercise;
}

Properties

data
IExercise
required
Single exercise object

Usage Examples

import { IExerciseData } from './types';

async function getExercises(
  page: number = 1,
  limit: number = 10
): Promise<IExerciseData> {
  const response = await fetch(
    `https://api.bodyworks.io/exercises?page=${page}&limit=${limit}`
  );
  return response.json();
}

// Type-safe usage
const exercises = await getExercises(1, 20);
console.log(`Total: ${exercises.totalExercises}`);
console.log(`Pages: ${exercises.totalPages}`);

exercises.data.forEach((exercise: IExercise) => {
  console.log(`${exercise.title} - ${exercise.target}`);
});

Type Guards

Create type guards to safely validate exercise data:
function isValidExercise(obj: any): obj is IExercise {
  return (
    typeof obj === 'object' &&
    typeof obj.name === 'string' &&
    typeof obj.title === 'string' &&
    typeof obj.target === 'string' &&
    typeof obj.bodyPart === 'string' &&
    typeof obj.equipment === 'string' &&
    Array.isArray(obj.images) &&
    Array.isArray(obj.videos) &&
    Array.isArray(obj.keywords)
  );
}

function isExerciseData(obj: any): obj is IExerciseData {
  return (
    typeof obj === 'object' &&
    typeof obj.totalExercises === 'number' &&
    typeof obj.totalPages === 'number' &&
    Array.isArray(obj.data) &&
    obj.data.every(isValidExercise)
  );
}

Build docs developers (and LLMs) love