Framework

Elixir Test Data Generation with MockHero

Client

defmodule MockHero do
  def generate(tables, seed \\ nil) do
    body = %{tables: tables}
    body = if seed, do: Map.put(body, :seed, seed), else: body

    Req.post!("https://api.mockhero.dev/api/v1/generate",
      json: body,
      headers: [
        {"x-api-key", System.get_env("MOCKHERO_API_KEY")}
      ]
    ).body
  end
end

data = MockHero.generate([
  %{name: "users", count: 50, fields: [
    %{name: "id", type: "uuid"},
    %{name: "email", type: "email"}
  ]},
  %{name: "posts", count: 200, fields: [
    %{name: "id", type: "uuid"},
    %{name: "user_id", type: "ref", ref: "users.id"},
    %{name: "title", type: "sentence"}
  ]}
], 42)

Get Started

Free API key.

M

MockHero Team

Guides and tutorials for generating realistic test data with the MockHero API.

Start generating test data for free

1,000 rows/month on the free tier. No credit card required.

Get Your API Key

Related Articles