Framework

Swift Test Data Generation with MockHero

Client

import Foundation

let body: [String: Any] = [
  "tables": [[
    "name": "users",
    "count": 50,
    "fields": [
      ["name": "id", "type": "uuid"],
      ["name": "name", "type": "full_name"]
    ]
  ]]
]

var req = URLRequest(url: URL(string: "https://api.mockhero.dev/api/v1/generate")!)
req.httpMethod = "POST"
req.setValue(ProcessInfo.processInfo.environment["MOCKHERO_API_KEY"], forHTTPHeaderField: "x-api-key")
req.setValue("application/json", forHTTPHeaderField: "Content-Type")
req.httpBody = try JSONSerialization.data(withJSONObject: body)

let (data, _) = try await URLSession.shared.data(for: req)
let json = try JSONSerialization.jsonObject(with: data) as! [String: Any]

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