| Crates.io | apicentric |
| lib.rs | apicentric |
| version | 0.4.1 |
| created_at | 2025-11-11 00:19:41.841255+00 |
| updated_at | 2026-01-26 00:16:39.253462+00 |
| description | Toolkit for building, recording, and sharing mock APIs |
| homepage | |
| repository | https://github.com/pmaojo/apicentric |
| max_upload_size | |
| id | 1926448 |
| size | 35,148,532 |
A powerful CLI tool and API simulator platform for developers who love the terminal
Apicentric is a Rust-based CLI tool and API simulator platform that helps developers:
Perfect for frontend developers who need backend APIs, teams doing contract testing, or anyone who loves working in the terminal.
Apicentric is built around a few core concepts:
Let's simulate a realistic e-commerce API with dynamic data, request validation, and multiple scenarios.
Create a file named ecommerce-api.yaml with the following content:
name: E-commerce API
version: "2.1"
description: Sample e-commerce API with products and orders
server:
port: 9002
base_path: /api/v2
fixtures:
products:
- id: 101
name: "Laptop Pro"
price: 1299.99
category: "electronics"
stock: 15
- id: 102
name: "Coffee Mug"
price: 12.50
category: "home"
stock: 50
endpoints:
- method: GET
path: /products
description: List products with optional filtering
parameters:
- name: category
in: query
required: false
type: string
responses:
200:
content_type: application/json
body: |
{
"products": [
{{#each fixtures.products}}
{
"id": {{id}},
"name": "{{name}}",
"price": {{price}},
"category": "{{category}}",
"stock": {{stock}}
}{{#unless @last}},{{/unless}}
{{/each}}
],
"total": {{fixtures.products.length}},
"filter": "{{query.category}}"
}
- method: POST
path: /orders
description: Create a new order
request_body:
content_type: application/json
schema: |
{
"customer_id": "number",
"items": [{"product_id": "number", "quantity": "number"}]
}
responses:
201:
content_type: application/json
body: |
{
"order_id": {{faker "datatype.number" min=1000 max=9999}},
"customer_id": {{request.body.customer_id}},
"items": {{json request.body.items}},
"total": {{faker "commerce.price"}},
"status": "pending",
"created_at": "{{now}}"
}
422:
condition: "{{not request.body.customer_id}}"
content_type: application/json
body: |
{
"error": "Invalid order",
"details": ["Customer ID is required"]
}
- method: GET
path: /orders/{id}/status
description: Get order status
responses:
200:
content_type: application/json
body: |
{
"order_id": {{params.id}},
"status": "{{#random}}pending,processing,shipped,delivered{{/random}}",
"updated_at": "{{now}}"
}
scenarios:
- name: "holiday_traffic"
description: "Simulate high traffic during holidays"
delay_ms: 1500
response_rate: 0.8
- name: "maintenance_mode"
description: "Service under maintenance"
response:
status: 503
headers:
Retry-After: "3600"
body: |
{
"error": "Service under maintenance",
"retry_after": "1 hour"
}
Run the following command in your terminal:
apicentric simulator start --services-dir .
Apicentric will start a server on port 9002.
Now you can send requests to your mock API:
Get all products:
curl http://localhost:9002/api/v2/products
Create a new order:
curl -X POST http://localhost:9002/api/v2/orders \
-H "Content-Type: application/json" \
-d '{
"customer_id": 12345,
"items": [
{"product_id": 101, "quantity": 1},
{"product_id": 102, "quantity": 2}
]
}'
Get order status:
curl http://localhost:9002/api/v2/orders/5678/status
This example demonstrates features like:
Create a portable Docker image for your service:
```bash
apicentric simulator dockerize --file ecommerce-api.yaml --output ./ecommerce-docker
This will create a Dockerfile and copy the service definition into the ecommerce-docker directory. You can then build and run the image:
cd ecommerce-docker
docker build -t ecommerce-api .
docker run -p 9002:9002 ecommerce-api
Apicentric provides multiple installation methods to suit your workflow. Choose the one that works best for you.
If you have Node.js installed, you can run Apicentric directly without installation:
npx apicentric simulator start
Or install it globally:
npm install -g apicentric
The easiest way to install on macOS and Linux:
brew install pmaojo/tap/apicentric
Verify installation:
apicentric --version
Update to latest version:
brew upgrade apicentric
Quick installation script for Linux and macOS:
curl -fsSL https://raw.githubusercontent.com/pmaojo/apicentric/main/scripts/install.sh | sh
This script will:
/usr/local/bin (requires sudo)Custom installation directory:
INSTALL_DIR=$HOME/.local/bin curl -fsSL https://raw.githubusercontent.com/pmaojo/apicentric/main/scripts/install.sh | sh
Verify installation:
apicentric --version
For Windows users, use the PowerShell installation script:
irm https://raw.githubusercontent.com/pmaojo/apicentric/main/scripts/install.ps1 | iex
This script will:
%USERPROFILE%\.apicentric\binVerify installation:
apicentric --version
If you have Rust installed, you can build from source with custom features:
Minimal build (fastest, ~1 minute):
cargo install apicentric --no-default-features --features minimal
Includes: Core simulator only
CLI Tools build (recommended, ~2 minutes):
cargo install apicentric --features cli-tools
Includes: Simulator, contract testing, and TUI
Full build (all features, ~3-5 minutes):
cargo install apicentric --features full
Includes: All features (TUI, P2P, GraphQL, scripting, AI)
Default build:
cargo install apicentric
Includes: Simulator and contract testing
Verify installation:
apicentric --version
Download pre-built binaries for your platform from GitHub Releases.
Available platforms:
apicentric-linux-x64.tar.gz)apicentric-macos-x64.tar.gz)apicentric-macos-arm64.tar.gz)apicentric-windows-x64.zip)Manual installation (Linux/macOS):
# Download the appropriate archive
curl -LO https://github.com/pmaojo/apicentric/releases/latest/download/apicentric-linux-x64.tar.gz
# Verify checksum (optional but recommended)
curl -LO https://github.com/pmaojo/apicentric/releases/latest/download/checksums.txt
sha256sum -c checksums.txt --ignore-missing
# Extract
tar -xzf apicentric-linux-x64.tar.gz
# Move to PATH
sudo mv apicentric /usr/local/bin/
# Make executable
sudo chmod +x /usr/local/bin/apicentric
Manual installation (Windows):
apicentric-windows-x64.zip from releasesapicentric.exe to a directory in your PATHVerify installation:
apicentric --version
You can use the dockerize command to create a self-contained Docker image for your services.
apicentric simulator dockerize --file <service1>.yaml [<service2>.yaml ...] --output ./my-service-docker
This will generate a Dockerfile and a .dockerignore file in the output directory, along with a services directory containing your service definitions.
You can then build and run the image:
cd my-service-docker
docker build -t my-service .
docker run -p <port>:<port> my-service
After installation, verify that Apicentric is working correctly:
# Check version
apicentric --version
# View help
apicentric --help
# List available commands
apicentric simulator --help
Expected output should show version information and available commands.
Apicentric includes built-in tools to help you manage your environment:
Diagnose issues with your installation or environment:
apicentric doctor
Quickly open the WebUI in your default browser:
apicentric open
# Or specify a custom port
apicentric open --port 9002
Issue: apicentric: command not found after installation
Solutions:
Homebrew: Ensure Homebrew's bin directory is in your PATH:
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc # or ~/.zshrc
source ~/.bashrc
Install script: Verify /usr/local/bin is in your PATH:
echo $PATH | grep -q "/usr/local/bin" && echo "✓ In PATH" || echo "✗ Not in PATH"
Windows: Restart your terminal or PowerShell after installation to refresh PATH
Cargo: Ensure ~/.cargo/bin is in your PATH:
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Issue: Permission errors during installation
Solutions:
Unix install script: The script requires sudo for /usr/local/bin. Use custom directory:
INSTALL_DIR=$HOME/.local/bin curl -fsSL https://raw.githubusercontent.com/pmaojo/apicentric/main/scripts/install.sh | sh
Then add to PATH:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Manual installation: Use sudo when moving to system directories:
sudo mv apicentric /usr/local/bin/
sudo chmod +x /usr/local/bin/apicentric
Issue: Checksum mismatch during installation
Solutions:
Download may be corrupted. Delete and try again:
rm apicentric-*.tar.gz
curl -LO https://github.com/pmaojo/apicentric/releases/latest/download/apicentric-linux-x64.tar.gz
Verify you're downloading from the official repository
Check your internet connection
Issue: Compilation errors when building from source
Solutions:
Update Rust: Ensure you have the latest stable Rust:
rustup update stable
Missing dependencies: Install required system dependencies:
sudo apt-get update
sudo apt-get install build-essential pkg-config libssl-dev
xcode-select --install
Try minimal build: If full build fails, try minimal:
cargo install apicentric --no-default-features --features minimal
Issue: Command shows "Feature not available in this build"
Solutions:
You installed a minimal build. Reinstall with desired features:
cargo install apicentric --features cli-tools --force
Or install full version:
brew reinstall apicentric # Homebrew includes cli-tools features
Issue: "apicentric cannot be opened because it is from an unidentified developer"
Solutions:
Option 1: Use Homebrew installation (recommended):
brew install pmaojo/tap/apicentric
Option 2: Allow the binary manually:
xattr -d com.apple.quarantine /usr/local/bin/apicentric
Option 3: Build from source with Cargo:
cargo install apicentric --features cli-tools
If you're still experiencing problems:
apicentric --version (if available)Define mock APIs in YAML and serve them locally:
record_unknownapicentric simulator import.apicentric simulator new-graphql <name>.Package your mock services into self-contained Docker images for easy deployment and sharing.
Dockerfile for one or more services.Validate that mocks match real APIs:
Generate client code from service definitions or export to standard formats:
apicentric simulator generate-types --file <service.yaml> --output <output.ts>apicentric simulator generate-query --file <service.yaml> --output <output.ts>apicentric simulator export --file <service.yaml> --output <openapi.json> --format openapiapicentric simulator export --file <service.yaml> --output <collection.json> --format postmanInteractive terminal dashboard for service management:
Apicentric supports the Model Context Protocol (MCP), allowing AI assistants like Claude, ChatGPT, and other MCP-compatible tools to interact with your API simulator programmatically.
MCP is an open protocol that enables AI models to securely access external tools and data sources. With MCP, AI assistants can:
Install with MCP support:
cargo install apicentric --features mcp
# or
brew install pmaojo/tap/apicentric # includes MCP
Configure your AI assistant:
For Claude Desktop (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"apicentric": {
"command": "apicentric",
"args": ["mcp"]
}
}
}
For VS Code (.vscode/mcp.json):
{
"servers": {
"apicentric": {
"type": "stdio",
"command": "apicentric",
"args": ["mcp"]
}
}
}
Start using MCP tools in your AI assistant:
"Create a mock API for a user management system with login and profile endpoints"
The AI will use MCP tools to automatically create and start the service!
list_services: List all available mock servicescreate_service: Create a new service from YAML definitionstart_service: Start a specific mock servicestop_service: Stop a running serviceget_service_logs: Retrieve logs for a serviceUser: "Create a REST API for managing books with CRUD operations"
AI Assistant (using MCP tools):
create_service to generate a books API YAMLstart_service to launch the API on a portget_service_logs that it's runningResult: A fully functional mock API ready for testing!
Transform Apicentric into a multi-protocol simulation engine for IoT and Industrial devices.
twin:
name: "Sensor_Presion_01"
physics:
- variable: "pressure"
strategy: "script"
params:
code: "value + 1.5"
transports:
- type: "mqtt"
broker_url: "localhost"
port: 1883
topic_prefix: "sensors/pressure"
client_id: "sensor_01"
apicentric twin run --device assets/library/demo_device.yaml
Note for Windows Users: The Plugin System is currently experimental and not supported on Windows environments due to dynamic library loading constraints.
Apicentric includes a comprehensive developer toolkit to streamline local work:
We use a supercomplete Makefile for all common tasks:
make build: Build both backend and frontendmake dev: Start a parallel development environmentmake test: Run the full test suitemake help: View all available targets (with a fancy ASCII logo!)For a guided experience, run our interactive wizard:
make wizard
This provides a numeric menu to build, test, and manage the project without remembering individual commands.
We welcome contributions! See CONTRIBUTING.md for guidelines.
MIT License - see LICENSE for details.
The crate follows hexagonal architecture principles and exposes the following modules:
app: Application bootstrap and command execution.
config: Configuration management for the simulator and tooling.
context: Shared runtime context and dependency wiring.
errors: Custom error types aligned with domain-driven design.
logging: Logging setup and tracing utilities.
utils: Cross-cutting helper functions.
validation: Input validation helpers used across adapters and domain logic.
storage: Persistence adapters for service specifications.
ai: AI-assisted tooling integrations.
cloud: Cloud synchronization utilities.
auth: Authentication helpers for collaborative scenarios.
domain: Core business rules and ports.
contract: Contract testing orchestration.
adapters: Infrastructure adapters that implement ports.
simulator: The API simulator runtime.
cli and cli_ui: CLI and text-based UI front-ends.
Refer to the module documentation for deeper implementation details.
Here is a visual walkthrough of the recording feature:



