SDKs overview

What The Commit provides a straightforward API for generating random, often humorous, commit messages. To facilitate integration for developers, both official and community-contcontributed Software Development Kits (SDKs) and libraries are available across several programming languages. These SDKs abstract the underlying HTTP requests, allowing developers to interact with the service using familiar language constructs, thereby reducing the boilerplate code required for API calls and response parsing. The primary utility of these tools lies in their ability to fetch a new commitment message with minimal setup, making them suitable for developer tools, internal scripts, or entertainment applications that require dynamic, light-hearted text.

The core functionality of What The Commit's API is to return a single, random commit message string. SDKs and libraries typically expose a simple method or function that, when invoked, performs an HTTP GET request to the What The Commit API endpoint and returns the message. This design simplifies the process for developers who wish to integrate this specific functionality without managing raw HTTP requests, parsing JSON (though the API often returns plain text), or handling potential network errors directly. The available SDKs aim to provide a consistent and idiomatic interface for each supported language, adhering to common coding conventions and package management practices.

Official SDKs by language

What The Commit maintains official SDKs for key programming languages, ensuring direct support and compatibility with the API. These official libraries are typically hosted on package managers specific to their respective ecosystems, making installation and dependency management straightforward. They are designed to encapsulate the API's core functionality, providing a simple interface to retrieve commit messages. The official SDKs are generally well-maintained and are the recommended approach for integrating What The Commit into applications.

Language Package Name Installation Command Maturity
Node.js whatthecommit npm install whatthecommit Stable
Python whatthecommit-py pip install whatthecommit-py Stable
Ruby whatthecommit-rb gem install whatthecommit-rb Stable
Go github.com/whatthecommit/go-whatthecommit go get github.com/whatthecommit/go-whatthecommit Stable

Each official SDK is developed to reflect the best practices of its respective language. For example, the Node.js package integrates with the asynchronous nature of JavaScript, often returning Promises for API calls. The Python library adheres to Pythonic conventions, providing a simple function call that blocks until a response is received or offers asynchronous options. Developers can review the official What The Commit website for the most current documentation and links to specific repository pages for each SDK.

Installation

Installing What The Commit SDKs typically involves using the standard package manager for your chosen programming language. The process is designed to be quick and integrate seamlessly into existing project workflows. Below are detailed installation instructions for the officially supported languages, demonstrating how to add the SDK as a dependency to your project.

Node.js

For Node.js projects, the whatthecommit package can be installed using npm or yarn. This will add the package to your project's node_modules directory and update your package.json file, making it available for import in your JavaScript or TypeScript files.

npm install whatthecommit
# or
yarn add whatthecommit

Python

Python developers can install the whatthecommit-py package using pip, Python's package installer. This command retrieves the package from PyPI (Python Package Index) and makes it available for import in your Python scripts or applications.

pip install whatthecommit-py

Ruby

Ruby projects can integrate the whatthecommit-rb gem via RubyGems. The gem install command downloads and installs the gem. For projects managed with Bundler, you would typically add gem 'whatthecommit-rb' to your Gemfile and then run bundle install.

gem install whatthecommit-rb

Go

Go modules are used to manage dependencies for Go projects. To install the Go SDK, use the go get command, which will fetch the module from its GitHub repository and add it to your project's dependencies, updating your go.mod file.

go get github.com/whatthecommit/go-whatthecommit

After installation, the SDK can be imported and utilized in your code. It's important to ensure your development environment has the respective package manager installed and configured correctly. For example, npm is bundled with Node.js, and pip is typically included with Python distributions, as detailed in the MDN Web Docs on JavaScript Promises.

Quickstart example

This section provides quickstart code snippets for retrieving a commit message using the official SDKs. These examples demonstrate the basic usage pattern: importing the library, calling the primary function to fetch a message, and then printing the result. Each example is designed to be runnable with minimal setup after installation.

Node.js Quickstart

The Node.js SDK provides an asynchronous function that returns a Promise, allowing for non-blocking API calls. The await keyword is used here for cleaner asynchronous code.

const whatthecommit = require('whatthecommit');

async function getRandomCommitMessage() {
  try {
    const message = await whatthecommit.getCommit();
    console.log('Random Commit Message (Node.js):', message);
  } catch (error) {
    console.error('Error fetching commit message:', error);
  }
}

getRandomCommitMessage();

Python Quickstart

The Python SDK typically offers a synchronous method for fetching the commit message, which is straightforward to use in scripts and applications.

import whatthecommit

try:
    message = whatthecommit.get_commit()
    print(f'Random Commit Message (Python): {message}')
except Exception as e:
    print(f'Error fetching commit message: {e}')

Ruby Quickstart

In Ruby, after requiring the gem, you can call a class method to retrieve the commit message. The example uses a simple puts statement to display the result.

require 'whatthecommit'

begin
  message = WhatTheCommit.get_commit
  puts "Random Commit Message (Ruby): #{message}"
rescue StandardError => e
  puts "Error fetching commit message: #{e}"
end

Go Quickstart

For Go, the SDK provides a function that returns the commit message and an error. Error handling is a standard part of Go programming, as illustrated in this example.

package main

import (
	"fmt"
	"log"

	"github.com/whatthecommit/go-whatthecommit"
)

func main() {
	message, err := whatthecommit.GetCommit()
	if err != nil {
		log.Fatalf("Error fetching commit message: %v", err)
	}
	fmt.Printf("Random Commit Message (Go): %s\n", message)
}

These examples illustrate the minimal code required to integrate What The Commit into your projects. Developers can expand upon these basics to incorporate error handling, custom logging, or integrate the messages into UI elements or command-line tools. The simplicity of the API and its SDKs is a core design principle, making it easy to use for its intended purpose of generating humorous placeholder text.

Community libraries

Beyond the official SDKs, the What The Commit API has inspired various community-contributed libraries and integrations. These libraries often extend functionality, provide wrappers for less common languages, or offer specific tools built around the commit message generation. While not officially supported, these community projects can be valuable for developers working in environments not covered by official SDKs or seeking specialized features.

Examples of community contributions might include:

  • PHP Client: A library for PHP developers to fetch commit messages, often available via Composer.
  • Rust Crate: A Rust-specific client for integrating into systems-level applications.
  • Command-Line Tools: Standalone executables or scripts that fetch and display a commit message directly from the terminal, useful for quick access or integration into shell scripts.
  • Browser Extensions: Integrations that display a new commit message on a browser tab or within development tools.

Developers interested in community libraries are encouraged to search public code repositories like GitHub for projects tagged with "whatthecommit" or "commit message generator". When using community-contributed code, it is advisable to review the project's documentation, license, and community activity to assess its stability and maintenance level. Community libraries can offer creative solutions and broader language support, but their longevity and bug fix responsiveness depend on individual contributors.

The open-source nature of many of these projects also allows developers to contribute improvements, bug fixes, or even create their own wrappers if an existing solution doesn't meet specific requirements. This collaborative environment enriches the ecosystem around What The Commit, providing more options for integration across diverse technical stacks, as is common with many developer APIs that gain traction among the developer community.