Skip to main content

Overview

The routine types define the structure for workout routines, including workout plans, summaries, and category data. These types provide comprehensive type safety for managing structured workout programs.

IRoutine

Represents a complete workout routine with all associated data.
types.d.ts
interface IRoutine {
  category: string[];
  routine: {
    routine_title: string;
    routine_description: string;
    routine_imageUrl: string;
    workout_plan: { heading: string; day_plan: string }[];
    workout_summary: {
      MainGoal: string;
      WorkoutType: string;
      TrainingLevel: string;
      ProgramDuration: string;
      DaysPerWeek: number;
      TimePerWorkout: string;
      EquipmentRequired: string;
      TargetGender: string;
    };
  };
  id_: number;
  id: number;
}

Properties

category
string[]
required
Array of category tags for the routine (e.g., [“strength”, “beginner”, “full-body”])
routine
object
required
Main routine object containing all workout details
id_
number
required
Alternative numeric identifier for the routine
id
number
required
Primary numeric identifier for the routine

IRoutinesResponse

Paginated response containing multiple routines.
types.d.ts
interface IRoutinesResponse {
  totalPages: number;
  totalRoutines: number;
  data: IRoutine[];
}

Properties

totalPages
number
required
Total number of pages available for pagination
totalRoutines
number
required
Total count of routines matching the query
data
IRoutine[]
required
Array of routine objects for the current page

IRoutineCategory

Represents a routine category with visual representation.
types.d.ts
interface IRoutineCategory {
  title: string;
  imageUrl: string;
}

Properties

title
string
required
Category title (e.g., “Strength Training”, “Weight Loss”)
imageUrl
string
required
Image URL representing the category

IRoutineCategoryResponse

Response containing routine categories and count.
types.d.ts
interface IRoutineCategoryResponse {
  data: {
    category: IRoutineCategory[];
  };
  totalRoutinesFilter: number;
}

Properties

data
object
required
Container for category data
totalRoutinesFilter
number
required
Total number of routines available across all categories

Usage Examples

import { IRoutinesResponse, IRoutine } from './types';

async function getRoutines(
  page: number = 1,
  category?: string
): Promise<IRoutinesResponse> {
  const params = new URLSearchParams({ page: page.toString() });
  if (category) params.append('category', category);
  
  const response = await fetch(
    `https://api.bodyworks.io/routines?${params}`
  );
  return response.json();
}

// Type-safe usage
const routines = await getRoutines(1, 'strength');
console.log(`Total: ${routines.totalRoutines}`);
console.log(`Pages: ${routines.totalPages}`);

routines.data.forEach((routine: IRoutine) => {
  console.log(routine.routine.routine_title);
  console.log(`Days/Week: ${routine.routine.workout_summary.DaysPerWeek}`);
});

Type Guards

Create type guards to safely validate routine data:
function isValidWorkoutSummary(obj: any): boolean {
  return (
    typeof obj === 'object' &&
    typeof obj.MainGoal === 'string' &&
    typeof obj.WorkoutType === 'string' &&
    typeof obj.TrainingLevel === 'string' &&
    typeof obj.ProgramDuration === 'string' &&
    typeof obj.DaysPerWeek === 'number' &&
    typeof obj.TimePerWorkout === 'string' &&
    typeof obj.EquipmentRequired === 'string' &&
    typeof obj.TargetGender === 'string'
  );
}

function isValidRoutine(obj: any): obj is IRoutine {
  return (
    typeof obj === 'object' &&
    Array.isArray(obj.category) &&
    typeof obj.routine === 'object' &&
    typeof obj.routine.routine_title === 'string' &&
    typeof obj.routine.routine_description === 'string' &&
    Array.isArray(obj.routine.workout_plan) &&
    isValidWorkoutSummary(obj.routine.workout_summary) &&
    typeof obj.id === 'number' &&
    typeof obj.id_ === 'number'
  );
}

Build docs developers (and LLMs) love