apimock

module
v0.0.0-...-952df67 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2025 License: MIT

README ยถ

apimock.codes

Free mock API service for testing and development - A modern, schema-driven alternative to JSONPlaceholder.

๐ŸŒ Live: https://apimock-opyavp46a-0xdps-team.vercel.app
๐Ÿ“š Docs: https://apimock-opyavp46a-0xdps-team.vercel.app/docs
๐ŸŽฎ Playground: https://apimock-opyavp46a-0xdps-team.vercel.app/playground

โœจ Features

  • ๐Ÿš€ Schema-Driven - Add new endpoints by creating JSON schemas (zero code!)
  • ๐ŸŽฏ RESTful API - Standard REST endpoints for all resources
  • ๐Ÿ’ก Realistic Data - Powered by gofakeit with 50+ generators
  • โšก Fast & Reliable - Go backend with Gin framework
  • ๐ŸŒ CORS Enabled - Ready for frontend development
  • ๐ŸŽจ Modern UI - Next.js website with interactive playground
  • ๐Ÿ“ฆ No Database - Generates data on-the-fly
  • ๐Ÿ†“ Free Forever - Open source and self-hostable

๐Ÿ“ฆ Project Structure

apimock/
โ”œโ”€โ”€ api/              # Go API server (Gin + gofakeit)
โ”‚   โ”œโ”€โ”€ main.go       # Entry point, dynamic route registration
โ”‚   โ”œโ”€โ”€ schema/       # Schema loader and data generator
โ”‚   โ”œโ”€โ”€ handlers/     # Generic resource handlers
โ”‚   โ””โ”€โ”€ shared/       # JSON schemas (copied for deployment)
โ”œโ”€โ”€ web/              # Next.js 14 website (TypeScript + Tailwind)
โ”‚   โ”œโ”€โ”€ app/          # Pages (landing, docs, playground)
โ”‚   โ”œโ”€โ”€ components/   # React components
โ”‚   โ””โ”€โ”€ shared/       # JSON schemas (copied for deployment)
โ”œโ”€โ”€ shared/           # Source of truth for schemas
โ”‚   โ””โ”€โ”€ schemas/      # Resource definitions (user, post, etc.)
โ””โ”€โ”€ vercel.json       # Monorepo deployment config

๐Ÿš€ Quick Start

Development Setup

1. Clone the repository:

git clone https://github.com/0xdps/fake-stack.git
cd fake-stack/apimock

2. Start the API:

cd api
go run main.go

API runs on http://localhost:8080

3. Start the website:

cd web
npm install
npm run dev

Website runs on http://localhost:3000

Using the API
# Get 10 users
curl http://localhost:8080/api/users?count=10

# Get single user by ID
curl http://localhost:8080/api/users/123

# Get resource metadata
curl http://localhost:8080/api/users/meta

# Get products
curl http://localhost:8080/api/products?count=50

๐Ÿ“š Available Resources

Resource Endpoint Fields
Users /api/users id, username, email, name, avatar, bio, etc.
Posts /api/posts id, user_id, title, content, published_at, etc.
Products /api/products id, name, description, price, category, etc.
Comments /api/comments id, post_id, user_id, content, created_at
Todos /api/todos id, user_id, title, completed, due_date
Reviews /api/reviews id, product_id, user_id, rating, comment

All endpoints support:

  • Collection: GET /api/{resource}?count=N (max 1000)
  • Single Item: GET /api/{resource}/:id
  • Metadata: GET /api/{resource}/meta

๐ŸŽฏ Schema-Driven Development

Adding a New Resource (Zero Code!)

1. Create a schema in shared/schemas/:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Order",
  "type": "object",
  "x-resource": {
    "name": "orders",
    "singular": "order",
    "description": "E-commerce orders",
    "routes": {
      "path": "/orders",
      "methods": ["GET"],
      "aliases": ["/purchases"]
    }
  },
  "properties": {
    "id": {
      "type": "integer",
      "x-generator": "random_int",
      "x-generator-params": { "min": 1, "max": 10000 }
    },
    "total": {
      "type": "number",
      "x-generator": "random_int",
      "x-generator-params": { "min": 10, "max": 500 }
    },
    "status": {
      "type": "string",
      "x-generator": "word"
    }
  }
}

2. Restart the server:

cd api && go run main.go

That's it! Your new endpoint is live at /api/orders ๐ŸŽ‰

Custom Routes

Define custom paths, aliases, and methods in schemas:

{
  "x-resource": {
    "name": "todos",
    "routes": {
      "path": "/v1/todos",
      "aliases": ["/tasks", "/todo-items"],
      "methods": ["GET", "POST"]
    }
  }
}

This creates:

  • โœ… GET /api/v1/todos
  • โœ… GET /api/tasks (alias)
  • โœ… GET /api/todo-items (alias)
Supported Generators
  • Personal: name, first_name, email, username, password
  • Address: address, city, country, zip_code, latitude
  • Company: company, job, catch_phrase
  • Internet: url, domain_name, ipv4, uuid, mac_address
  • Dates: date, date_time, past_date, future_date
  • Text: word, sentence, paragraph, text
  • Numbers: random_int, random_digit, random_number
  • Other: phone_number, boolean, user_agent

๐Ÿš€ Deployment

Deploy to Vercel (Monorepo)

1. Install Vercel CLI:

npm install -g vercel

2. Link project:

cd apimock
vercel link

3. Deploy:

vercel --prod

The deployment configuration in vercel.json automatically:

  • Builds the Next.js website
  • Creates serverless functions for the Go API
  • Routes /api/* to the API
  • Routes everything else to the website
Environment Variables

Set in Vercel dashboard:

NEXT_PUBLIC_API_URL=https://your-api-domain.vercel.app
Custom Domains

Configure in Vercel project settings:

  • Website: apimock.codes โ†’ /
  • API: api.apimock.codes โ†’ /api
Disable Deployment Protection
  1. Go to https://vercel.com/[your-team]/apimock/settings/deployment-protection
  2. Select "Disabled" or "Standard" mode
  3. Redeploy if necessary

๐Ÿ› ๏ธ Technology Stack

Backend (API)
  • Language: Go 1.22+
  • Framework: Gin v1.11.0
  • Data Generation: gofakeit/v7
  • CORS: gin-contrib/cors
Frontend (Website)
  • Framework: Next.js 14 (App Router)
  • Language: TypeScript
  • Styling: Tailwind CSS
  • Deployment: Vercel Serverless

๐Ÿ“– Documentation

API Documentation

Visit the /docs page for:

  • Quick start guide (4 languages: JavaScript, cURL, Python, Node.js)
  • Complete endpoint reference
  • Schema documentation for all resources
  • Live "Try It" buttons
Interactive Playground

Visit the /playground page to:

  • Test endpoints without writing code
  • Select resources and endpoint types
  • Adjust parameters (count, ID)
  • See live JSON responses
  • Copy code examples (cURL, JavaScript, Python)

๐Ÿค Contributing

Contributions welcome! The easiest way to contribute is to add new resource schemas:

  1. Create shared/schemas/your-resource.json
  2. Test locally with cd api && go run main.go
  3. Submit a PR

See ../CONTRIBUTING.md for detailed guidelines.

  • fakestack - Database population tool (Python, Node.js, Go)
  • Parent project that powers the data generation

๐Ÿ“„ License

MIT License - see ../LICENSE

๐Ÿ™ Acknowledgments

Built with:


Made with โค๏ธ by Devendra Pratap

Directories ยถ

Path Synopsis
api module
lib

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL