SDKs overview

Bored provides Software Development Kits (SDKs) and libraries designed to facilitate the programmatic interaction with its API mocking platform. These tools enable developers to integrate API mocking capabilities directly into their development and testing workflows, supporting various programming languages and environments. The primary goal of these SDKs is to simplify the creation, configuration, and management of mock endpoints and responses, enabling frontend development, rapid API prototyping, and deterministic API testing without reliance on live backend services. For a comprehensive understanding of the API's capabilities, developers can refer to the Bored API reference documentation.

The SDKs are built to interact with the Bored platform's core functionalities, which include defining mock endpoints, specifying response bodies, configuring HTTP status codes, and managing response headers. This allows for fine-grained control over the mock API's behavior, simulating various real-world scenarios, including error conditions, latency, and specific data responses. By abstracting the HTTP request/response logic, SDKs streamline the development process, allowing engineers to focus on application logic rather than low-level API communication details. For example, using an SDK can simplify the process of setting up a mock endpoint that returns a specific JSON object, as detailed in the Bored developer documentation.

While Bored is a cloud-based service, its SDKs are designed for local integration into development projects, allowing for efficient API interaction. This approach aligns with modern development practices that emphasize local development and testing workflows before deployment. The SDKs often provide utilities for authentication, request signing, and error handling, which are common requirements when interacting with cloud-based APIs. For instance, an SDK might include methods to automatically attach API keys to requests, which is a standard practice for securing API access, as described in many cloud provider security credential guides.

Official SDKs by language

Bored offers official SDKs to support integration into common development environments. These SDKs are maintained by the Bored team and provide idiomatic interfaces for interacting with the platform's API mocking features. The following table outlines the currently available official SDKs, their respective package managers, and installation commands.

Language Package Name Installation Command Maturity
Node.js @bored/sdk-nodejs npm install @bored/sdk-nodejs Stable
Python bored-sdk-python pip install bored-sdk-python Stable
Go github.com/bored/bored-go-sdk go get github.com/bored/bored-go-sdk Beta

Each official SDK is designed to encapsulate the underlying HTTP requests and responses, providing a higher-level, language-specific interface. This design simplifies common tasks such as creating mock endpoints, updating mock responses, and fetching request logs. Developers can consult the Bored documentation portal for detailed API references and usage guides specific to each SDK.

Installation

Installing Bored's official SDKs typically involves using the standard package manager for the respective programming language. Below are detailed installation instructions for the Node.js, Python, and Go SDKs.

Node.js SDK

The Node.js SDK for Bored is distributed via npm, the Node.js package manager. To install it, open your terminal or command prompt and run the following command within your project directory:

npm install @bored/sdk-nodejs

After installation, you can import the SDK into your JavaScript or TypeScript files:

import { BoredClient } from '@bored/sdk-nodejs';
// Or for CommonJS:
// const { BoredClient } = require('@bored/sdk-nodejs');

Python SDK

The Python SDK is available on PyPI and can be installed using pip, the Python package installer. Execute the following command in your terminal:

pip install bored-sdk-python

Once installed, you can import the SDK into your Python scripts:

from bored_sdk import BoredClient

Go SDK

The Go SDK is hosted on GitHub and can be fetched using Go Modules. Navigate to your project directory and run:

go get github.com/bored/bored-go-sdk

You can then import the package into your Go source files:

import "github.com/bored/bored-go-sdk"

Ensure your Go environment is properly configured for module management. The official Go documentation on managing dependencies provides further context.

Quickstart example

This quickstart example demonstrates how to create a simple mock endpoint using the Bored Node.js SDK. This example assumes you have already installed the @bored/sdk-nodejs package and have a Bored API key available. For setting up an API key, refer to the Bored authentication guide.

Prerequisites

  • Node.js installed
  • @bored/sdk-nodejs installed
  • Bored API Key (e.g., stored as an environment variable BORED_API_KEY)

Example Code (Node.js)

import { BoredClient } from '@bored/sdk-nodejs';

const API_KEY = process.env.BORED_API_KEY;

if (!API_KEY) {
  console.error('BORED_API_KEY environment variable is not set.');
  process.exit(1);
}

const bored = new BoredClient({ apiKey: API_KEY });

async function createMockEndpoint() {
  try {
    const mock = await bored.createMock({
      path: '/api/users',
      method: 'GET',
      response: {
        statusCode: 200,
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify([
          { id: 1, name: 'Alice' },
          { id: 2, name: 'Bob' }
        ])
      }
    });

    console.log('Successfully created mock endpoint:');
    console.log(`Mock ID: ${mock.id}`);
    console.log(`Access at: ${mock.url}`); // This URL points to your live mock

    // Example: Fetch existing mocks
    const existingMocks = await bored.listMocks();
    console.log('\nCurrently active mocks:');
    existingMocks.forEach(m => console.log(`- ${m.method} ${m.path} (${m.url})`));

  } catch (error) {
    console.error('Error creating mock endpoint:', error.message);
  }
}

createMockEndpoint();

Explanation

  1. Initialization: The BoredClient is initialized with your API key. This client manages authenticated requests to the Bored API.
  2. createMock Call: The createMock method is used to define a new mock endpoint. It takes an object specifying the HTTP method (GET), path (/api/users), and the desired response (statusCode, headers, body).
  3. Response Handling: The method returns a mock object containing details about the created mock, including its unique id and the url where it can be accessed.
  4. Listing Mocks: The listMocks method demonstrates how to retrieve all currently active mocks associated with your API key, providing an overview of your configured endpoints.

This example sets up a mock API endpoint accessible via a unique URL provided by Bored. Any requests made to this URL will receive the predefined JSON response. This capability is fundamental for enabling parallel frontend and backend development, as frontend teams can proceed with development against stable, predictable API responses.

Community libraries

While Bored maintains official SDKs for key programming languages, the open nature of its API allows for the development of community-contributed libraries and tools. These libraries often extend functionality, provide integrations with specific frameworks, or offer alternative language bindings not officially supported. Community efforts can significantly broaden the ecosystem around an API, as discussed in various Google developer resources on community SDKs.

As of the current date, specific community libraries for Bored are emerging. Developers looking for such contributions are encouraged to explore platforms like GitHub, GitLab, and relevant package repositories (e.g., npm, PyPI, Maven Central) using keywords such as bored-api, bored-mock, or bored-client. These repositories are common places where developers publish and share their open-source projects.

Before integrating any community-contributed library, it is advisable to:

  • Review the source code: Assess the quality, security, and adherence to best practices.
  • Check documentation and examples: Ensure the library is well-documented and easy to use.
  • Examine community activity: Look for active maintenance, recent updates, and responsive issue tracking.
  • Understand licensing: Confirm the license is compatible with your project's requirements.

The Bored team encourages community contributions that enhance the developer experience. Information about contributing to the Bored ecosystem or finding community projects may be available in the Bored community section of the documentation or through the official Bored developer forums.