SDKs overview

The PoetryDB API provides a RESTful interface for accessing poetry data, including poems by title, author, and random selections. As a simple, unauthenticated public API, direct HTTP requests are often sufficient for integration. However, Software Development Kits (SDKs) and community-contributed libraries can simplify this process by providing language-specific wrappers that handle HTTP requests, JSON parsing, and error handling, allowing developers to interact with the API using native programming constructs.

While PoetryDB does not offer official, first-party SDKs maintained by the API provider, its open and accessible nature has encouraged the development of community-driven libraries. These libraries cater to popular programming languages, offering convenient methods and data structures to work with poetry data. Developers can also generate client libraries using tools that process the OpenAPI Specification (OAS) if a specification document is available, which defines RESTful APIs in a machine-readable format (OpenAPI Specification FAQs).

Official SDKs by language

As of May 2026, PoetryDB does not provide official SDKs directly maintained by its developers. The API is designed for direct consumption via standard HTTP requests, making a dedicated official SDK less critical for basic usage. Developers typically send HTTP GET requests to specific endpoints and parse the JSON responses in their chosen programming language. This approach aligns with the API's goal of providing a straightforward, free testing resource.

The absence of official SDKs means developers rely on standard HTTP client libraries available in most programming languages (e.g., requests in Python, fetch in JavaScript, HttpClient in C#) or community-maintained wrappers. Organizations like Kong, an API Gateway provider, note that API providers often decide whether to offer SDKs based on API complexity, target audience, and resource availability.

Installation

Since PoetryDB primarily uses direct HTTP requests and does not have official SDKs, installation typically involves setting up HTTP client libraries for your chosen programming language. For community libraries, installation is usually handled via standard package managers.

Python

To use the community-maintained poetrydb library for Python, install it via pip:

pip install poetrydb

If you prefer to make direct HTTP requests, Python's requests library is a common choice:

pip install requests

JavaScript (Node.js/Browser)

For Node.js environments, a community library like node-poetrydb can be installed via npm:

npm install node-poetrydb

Alternatively, for direct HTTP requests in Node.js, you can use the built-in fetch API (available in newer Node.js versions or via polyfill) or the axios library:

npm install axios

In web browsers, the native Fetch API is standard for making HTTP requests:

// No installation needed, it's built-in

Ruby

For Ruby, the net/http module is built-in. For more advanced features, the httparty gem is popular for making HTTP requests:

gem install httparty

PHP

PHP has built-in functions like file_get_contents or cURL for HTTP requests. The Composer package manager can be used for more robust HTTP clients like Guzzle:

composer require guzzlehttp/guzzle

Quickstart example

These examples demonstrate how to fetch a list of all authors from PoetryDB.

Python (using requests)

This snippet uses the popular Python requests library to fetch and print the first five authors.

import requests

def get_all_authors():
    url = "https://freetestapi.com/api/v1/PoetryDB/author"
    try:
        response = requests.get(url)
        response.raise_for_status()  # Raise HTTPError for bad responses (4xx or 5xx)
        authors = response.json()
        print("First 5 authors:")
        for author in authors[:5]:
            print(f"- {author}")
    except requests.exceptions.RequestException as e:
        print(f"Error fetching authors: {e}")

if __name__ == "__main__":
    get_all_authors()

JavaScript (Node.js using fetch)

This example demonstrates fetching authors in a Node.js environment using the native fetch API.

async function getAllAuthors() {
    const url = "https://freetestapi.com/api/v1/PoetryDB/author";
    try {
        const response = await fetch(url);
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        const authors = await response.json();
        console.log("First 5 authors:");
        authors.slice(0, 5).forEach(author => console.log(`- ${author}`));
    } catch (error) {
        console.error("Error fetching authors:", error);
    }
}

getAllAuthors();

Ruby (using net/http)

This Ruby example utilizes the built-in net/http library to retrieve author data.

require 'net/http'
require 'uri'
require 'json'

def get_all_authors
  uri = URI.parse("https://freetestapi.com/api/v1/PoetryDB/author")
  response = Net::HTTP.get_response(uri)

  if response.is_a?(Net::HTTPSuccess)
    authors = JSON.parse(response.body)
    puts "First 5 authors:"
    authors[0..4].each do |author|
      puts "- #{author}"
    end
  else
    puts "Error fetching authors: #{response.code} #{response.message}"
  end
rescue StandardError => e
  puts "An error occurred: #{e.message}"
end

get_all_authors

Community libraries

Community-contributed libraries extend the reach of the PoetryDB API by offering language-specific abstractions. These libraries are typically open-source and maintained by developers who find the API useful for their projects. They often provide functions that map directly to API endpoints, simplifying common queries.

While their maintenance and feature sets can vary compared to official SDKs, they serve as valuable tools for quick integration. Developers should review the latest documentation and community activity for any third-party library before integrating it into production environments. Notable examples include:

Python: poetrydb

  • Description: A Python wrapper for the PoetryDB API, providing convenient methods to query poems, authors, and titles.
  • Installation: pip install poetrydb
  • Usage Example:
    from poetrydb import PoetryDB
    
    # Get all authors
    authors = PoetryDB.authors()
    print(f"Number of authors: {len(authors)}")
    
    # Get poems by a specific author
    poems_by_author = PoetryDB.author("William Shakespeare")
    if poems_by_author:
        print(f"First poem by William Shakespeare: {poems_by_author[0]['title']}")
    
    # Get a random poem
    random_poem = PoetryDB.random()
    if random_poem:
        print(f"Random poem: {random_poem[0]['title']} by {random_poem[0]['author']}")
    

JavaScript/Node.js: node-poetrydb

  • Description: A Node.js client library for PoetryDB, designed to be used in Node.js applications.
  • Installation: npm install node-poetrydb
  • Usage Example:
    const PoetryDB = require('node-poetrydb');
    
    async function usePoetryDB() {
      // Get all authors
      const authors = await PoetryDB.authors();
      console.log(`Number of authors: ${authors.length}`);
    
      // Get poems by a specific title (case-insensitive search)
      const poemsByTitle = await PoetryDB.title("Sonnet 18");
      if (poemsByTitle.length > 0) {
        console.log(`Poem with title 'Sonnet 18': ${poemsByTitle[0].author}`);
      }
    
      // Get random poems (e.g., 2 random poems)
      const randomPoems = await PoetryDB.random(2);
      if (randomPoems.length > 0) {
        console.log(`Random poem 1: ${randomPoems[0].title} by ${randomPoems[0].author}`);
      }
    }
    
    usePoetryDB();
    

Table of Community Libraries

The following table summarizes known community libraries for PoetryDB. This list is not exhaustive and reflects common usage patterns. Developers are encouraged to search package repositories (e.g., PyPI, npm) for the most current options.

Language Package Name Install Command Maturity / Status
Python poetrydb pip install poetrydb Community-maintained, active
JavaScript (Node.js) node-poetrydb npm install node-poetrydb Community-maintained, moderate activity