Boclips API Client

113.5.2 · active · verified Tue Apr 21

The Boclips API Client is a JavaScript/TypeScript library designed to provide frontend applications with a structured interface for interacting with the Boclips API. Currently at version 113.5.2, this client likely follows a rapid release cadence, indicated by its high major version number, suggesting frequent updates aligned with backend API evolution. A key differentiator is its robust testing strategy leveraging Pact for contract testing, which generates contracts against a mock HTTP layer and then verifies them against the staging API gateway. This ensures client-backend compatibility without relying solely on brittle end-to-end integration tests. The library also includes a `FakeBoclipsClient` implementation, offering an in-memory test client that simplifies integration testing for consumer applications by removing the need for HTTP mocks. Users are expected to provide their own configured Axios instance, including authentication, to the client.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates the initialization of the `ApiBoclipsClient` with an Axios instance and how to access a sub-client to fetch data.

import { ApiBoclipsClient } from 'boclips-api-client';
import axios from 'axios';

const initializeClient = async () => {
  // In a real application, replace this with your actual environment variable or configuration.
  const apiUrlPrefix = process.env.BOCLIPS_API_URL_PREFIX ?? 'https://api.staging-boclips.com';

  // Configure Axios. This is where you'd typically set up authentication (e.g., Bearer tokens).
  const axiosInstance = axios.create({
    baseURL: apiUrlPrefix,
    headers: {
      // Example: 'Authorization': `Bearer ${yourAuthToken}`
    }
  });

  try {
    const client = await ApiBoclipsClient.initialize(axiosInstance, apiUrlPrefix);

    // Example: Query an existing collection
    const sampleCollectionId = 'sample-collection-id'; // Replace with a real ID for testing
    const existingCollection = await client.collectionsClient.get(sampleCollectionId);

    console.log(`Successfully fetched collection: ${existingCollection?.title}`);
    return existingCollection;
  } catch (error) {
    console.error('Failed to initialize BoclipsClient or fetch collection:', error);
    throw error;
  }
};

// To run this example, ensure you have an environment variable for the API prefix
// and handle authentication in your axios instance.
// initializeClient();

view raw JSON →