SDKs overview
Mockaroo provides a RESTful API for programmatic access to its data generation capabilities, allowing developers to integrate synthetic data creation into their applications, test suites, and build pipelines. While direct HTTP requests are a common method for interaction, SDKs and community-contributed libraries abstract the underlying API calls, offering language-specific constructs for easier integration.
These tools typically handle API authentication, request formatting, and response parsing, reducing the boilerplate code required to fetch generated data in various formats such as JSON, CSV, or SQL. The primary benefit of using an SDK or library is to streamline the process of obtaining consistent and realistic test data directly within a development environment, supporting practices like continuous integration and automated testing.
The Mockaroo API allows users to request data based on pre-defined schemas or dynamically defined fields, supporting a range of data types and formats. For details on the underlying API, refer to the Mockaroo API documentation.
Official SDKs by language
Mockaroo maintains an official client library for Ruby, which provides a direct interface to its API. This library simplifies common tasks such as fetching generated data and managing schemas, aligning with Ruby development workflows.
| Language | Package/Library Name | Maturity | Description |
|---|---|---|---|
| Ruby | mockaroo-client |
Official, Maintained | A Ruby client for the Mockaroo API, facilitating data generation and schema management. |
Installation
Installation instructions vary by language and package manager. The following provides common methods for the official Ruby SDK and examples for popular languages often supported by community libraries.
Ruby
The official Mockaroo client for Ruby is distributed as a Gem, which can be installed using Bundler or RubyGems:
# Using RubyGems
gem install mockaroo-client
# Using Bundler (add to your Gemfile)
gem 'mockaroo-client'
After installation, the library can be required in Ruby projects:
require 'mockaroo-client'
Python (Community Example)
While there is no official Python SDK from Mockaroo, community libraries often leverage pip for installation. An example might look like this:
pip install python-mockaroo-client # Example package name
Node.js (Community Example)
For Node.js, community libraries are typically installed via npm or yarn:
# Using npm
npm install mockaroo-data-generator # Example package name
# Using yarn
yarn add mockaroo-data-generator
Quickstart example
This example demonstrates how to use the official mockaroo-client Ruby Gem to fetch generated data based on a pre-defined schema. Prior to execution, ensure your Mockaroo API key is available. You can find your API key on your Mockaroo API page.
Ruby Quickstart
First, create a schema in Mockaroo and note its name. For instance, a schema named users with fields like id (Row Number), first_name (First Name), and email (Email Address).
require 'mockaroo-client'
# Replace with your actual Mockaroo API key
API_KEY = ENV['MOCKAROO_API_KEY'] || 'YOUR_MOCKAROO_API_KEY_HERE'
# Initialize the client
client = Mockaroo::Client.new(api_key: API_KEY)
begin
# Fetch 5 records from a schema named 'users'
# The 'format' parameter specifies the output format (e.g., :json, :csv)
users_data = client.generate({
count: 5,
schema: 'users',
format: :json
})
puts "Generated Users Data (JSON):"
puts JSON.pretty_generate(users_data)
# Example for fetching CSV data directly, without a predefined schema
# This uses inline field definitions
inline_data = client.generate({
count: 3,
format: :csv,
fields: [
{ name: 'product_name', type: 'Product Name' },
{ name: 'price', type: 'Price', min: 10, max: 100, decimals: 2 }
]
})
puts "\nGenerated Inline Data (CSV):"
puts inline_data
rescue Mockaroo::Client::Error => e
puts "Error fetching data: #{e.message}"
puts "Check your API key and schema name."
end
This Ruby example demonstrates how to retrieve data using both a named schema and inline field definitions. The generate method handles the API request and parses the response into the specified format, such as a Ruby Hash for JSON or a String for CSV.
General API Interaction (HTTP)
For languages without a dedicated SDK, direct HTTP requests are commonly used. The Mockaroo API supports standard HTTP methods (primarily GET for data generation) and accepts parameters in the query string. Authentication is typically handled via an API key passed as a query parameter or a custom header, as detailed in the Mockaroo API documentation. Developers can use standard HTTP client libraries available in most programming languages, such as requests in Python or fetch in JavaScript. This interaction pattern is common for many RESTful APIs, as described in MDN Web Docs on REST.
Community libraries
The Mockaroo developer community has contributed libraries and wrappers in various languages to simplify interaction with the API beyond the officially supported Ruby client. These libraries often wrap the RESTful API, providing idiomatic interfaces for languages like Python, Node.js, and Go. While not officially maintained by Mockaroo, they can offer a convenient way to integrate Mockaroo's data generation into diverse tech stacks.
When using community-contributed libraries, it is advisable to review their documentation, community support, and maintenance status. Common places to find these libraries include:
- GitHub: Searching GitHub for "Mockaroo client" or "Mockaroo API wrapper" in combination with a specific language (e.g., "Mockaroo Python client") often yields relevant projects.
- Package Registries: Language-specific package managers (e.g., PyPI for Python, npm for Node.js, Go Modules for Go) may list community libraries.
Examples of languages where community libraries might exist include:
- Python: Libraries that wrap the Mockaroo API to generate data, often returning Python dictionaries or Pandas DataFrames.
- Node.js: JavaScript packages available via npm that provide methods for fetching data, suitable for Node.js backend services or frontend build tools.
- Go: Go modules that offer type-safe access to Mockaroo's API, aligning with Go's strong typing conventions.
Developers are encouraged to consult the Mockaroo community forums or official documentation channels for any recommended third-party integrations, though direct recommendations are not typically provided for unofficial tools.