mrapids 0.1.31

Your OpenAPI, but executable
Documentation
# How MicroRapid Solves Common API Tooling Problems

## Overview

This document analyzes how MicroRapid addresses the major pain points in API development tooling, with concrete examples and evidence.

---

## 🔁 Client Generation Issues

### Traditional Problem:
- **Bloated code**: Swagger Codegen generates 1000s of lines for simple APIs
- **Hard to customize**: Generated code is overwritten on regeneration
- **Weak OpenAPI 3.1 support**: Most generators don't support newer features

### ✅ MicroRapid's Solution: NO CODE GENERATION

Instead of generating code, MicroRapid **executes specs directly**:

```bash
# Traditional approach (generates 50+ files):
swagger-codegen generate -i api.yaml -l python -o ./client
python client/api_client.py  # Use generated code

# MicroRapid approach (zero files):
mrapids run createUser --data @user.json
```

**Evidence**:
- Kubernetes API (8.7MB spec) → Traditional: ~100K lines of generated code
- MicroRapid: 0 lines, instant execution

**Benefits**:
- ✅ No code to maintain
- ✅ Always uses latest spec
- ✅ No regeneration needed
- ✅ Works with any OpenAPI version that parses

---

## 🔍 Debugging Issues

### Traditional Problem:
- No inline validation
- Generic HTTP errors
- No schema-aware error reporting
- Hard to debug what went wrong

### ✅ MicroRapid's Solution: BUILT-IN DEBUGGING

**1. Verbose Mode with Full Request Details**:
```bash
mrapids run createUser -v --dry-run

# Output:
Building request for operation: createUser
Operation path: /users
Processing 2 generic parameters
Checking if 'name' is in path '/users' (pattern: '{name}')
Adding query parameter: name = john

📋 Request Details:
  Method: POST
  Path: /users
  Base URL: https://api.example.com
  Headers:
    Accept: application/json
    User-Agent: MicroRapid/0.1.0
```

**2. Dry Run for Safety**:
```bash
# See exactly what would be sent
mrapids run deleteUser --param id=123 --dry-run
```

**3. Schema Validation** (when available):
```bash
mrapids validate api.yaml

# Output:
❌ Errors: Found 1 error(s):
   • paths./users/{userId}.get - Path parameter 'userId' is not defined
⚠️  Warnings: Found 5 warning(s):
   • components.schemas.User - Schema is defined but never used
```

---

## 🔧 Extensibility Issues

### Traditional Problem:
- Poor CI/CD integration
- Hard to automate
- Doesn't fit DevOps workflows
- Requires custom scripting

### ✅ MicroRapid's Solution: NATIVE CLI DESIGN

**1. CI/CD Ready**:
```yaml
# .github/workflows/api-test.yml
- name: Test API Endpoints
  run: |
    mrapids test api.yaml --all
    mrapids run healthCheck || exit 1
```

**2. Unix Philosophy - Composable**:
```bash
# Chain with other tools
mrapids run listUsers | jq '.[] | .email' > emails.txt
mrapids run getUser --param id=123 | grep -q "active" && echo "User is active"
```

**3. Multiple Output Formats**:
```bash
# Human readable
mrapids list

# Machine readable
mrapids list --format json | jq '.operations[].operationId'
mrapids show getUser --format yaml
```

**4. Test Script Generation**:
```bash
# Generate test infrastructure
mrapids setup-tests api.yaml --format npm
npm test

# Or for CI
mrapids setup-tests api.yaml --format shell
./api-test.sh all
```

---

## 🔒 Authentication Issues

### Traditional Problem:
- Awkward OAuth2 handling
- Dynamic headers are painful
- Token refresh not automated
- Different auth per environment

### ✅ MicroRapid's Solution: FIRST-CLASS AUTH SUPPORT

**1. OAuth2 Made Simple**:
```bash
# Setup OAuth (with guided flow)
mrapids auth login github
# Opens browser, handles callback, stores tokens

# Use in requests
mrapids run listRepos --auth github
```

**2. Multiple Auth Profiles**:
```bash
# Different auth for different APIs
mrapids auth login prod-api --profile production
mrapids auth login staging-api --profile staging

# List all
mrapids auth list
🔐 Auth Profiles:
  • github (OAuth2)
  • prod-api (Bearer)
  • staging-api (API Key)
```

**3. Automatic Token Refresh**:
```bash
# Handles refresh automatically
mrapids run getUser --auth github
# If token expired, auto-refreshes before request
```

**4. Environment-Specific Auth**:
```bash
# Development
mrapids run createUser  # Uses dev credentials

# Production
mrapids run createUser --env production  # Uses prod credentials
```

**5. Dynamic Headers**:
```bash
# Add any headers dynamically
mrapids run getUser \
  --header "X-Tenant-ID: customer123" \
  --header "X-Feature-Flag: new-ui"
```

---

## 🧠 Developer Experience (DX) Issues

### Traditional Problem:
- Difficult to explore APIs quickly
- Can't use from terminal easily
- Need to write code for simple tests
- Documentation separate from execution

### ✅ MicroRapid's Solution: TERMINAL-FIRST DX

**1. Instant API Exploration**:
```bash
# See all operations
mrapids list
┌────────────────────────────────────────────────────┐
│              Available Operations (25 total)         │
├────┬───────────────┬────────┬──────────────┬────────┤
│ # │ Operation ID  │ Method │     Path     │ Example │
└────┴───────────────┴────────┴──────────────┴────────┘

# Search operations
mrapids list --filter user
# Shows only user-related operations

# Get operation details
mrapids show createUser
```

**2. Zero Setup Testing**:
```bash
# Test API in 3 commands
mrapids init my-api --from-file api.yaml
cd my-api
mrapids run listUsers
```

**3. Interactive Examples**:
```bash
# Generate examples for all operations
mrapids analyze --all

# Run with example data
mrapids run createUser  # Auto-uses generated example
```

**4. Smart Parameter Handling**:
```bash
# Path parameters auto-detected
mrapids run getUser --param userId=123
# Automatically places in: /users/{userId}

# Query parameters
mrapids run listUsers --param limit=10 --param offset=20
# Becomes: /users?limit=10&offset=20
```

**5. Helpful Error Messages**:
```bash
mrapids run createUser
# Error: Missing required request body. Use --data or --data @file.json

mrapids run getUser
# Error: Missing required parameter 'userId'. Use --param userId=VALUE
```

---

## 📚 Multi-Format Issues

### Traditional Problem:
- Postman collections ≠ OpenAPI
- Can't use gRPC from same tool
- GraphQL requires different clients
- Need multiple tools for different APIs

### ✅ MicroRapid's Current State & Vision

**Currently Supported**:
- ✅ OpenAPI 3.0.x (recommended)
- ✅ OpenAPI 3.1 (basic features)
- ✅ Swagger 2.0
- ✅ JSON and YAML formats

**Architecture Ready For**:
```rust
// Unified internal model supports multiple formats
pub struct UnifiedSpec {
    pub info: ApiInfo,
    pub operations: Vec<UnifiedOperation>,
    pub base_url: String,
}

// Easy to add new formats
match detect_format(&content) {
    Format::OpenAPI3 => parse_openapi_v3(&content),
    Format::Swagger2 => parse_swagger_v2(&content),
    Format::GraphQL => parse_graphql(&content),    // Future
    Format::GRPC => parse_proto(&content),          // Future
    Format::Postman => parse_postman(&content),     // Future
}
```

**Future Multi-Format Vision**:
```bash
# Same commands, different formats
mrapids run createUser              # OpenAPI
mrapids run CreateUser              # gRPC
mrapids run 'mutation { createUser }' # GraphQL
mrapids run {{baseUrl}}/users       # Postman
```

---

## 📊 Comparative Analysis

| Feature | Traditional Tools | MicroRapid |
|---------|------------------|------------|
| **Setup Time** | 30+ min (generate, configure) | 30 sec (init, run) |
| **Code Generated** | 1000s of lines | 0 lines |
| **API Changes** | Regenerate & redeploy | Instant (reads latest spec) |
| **Debugging** | Console.log/print debugging | Built-in verbose mode |
| **CI/CD** | Complex integration | Native CLI commands |
| **Auth** | Manual token handling | Automated OAuth flows |
| **Learning Curve** | Learn generated API | Use existing knowledge |
| **Multi-Format** | Different tool per format | Unified interface (planned) |

---

## 🎯 Real-World Impact

### Case Study: Testing Kubernetes API

**Traditional Approach**:
1. Generate client: ~15 minutes
2. 100K+ lines of code generated
3. Write test script
4. Handle auth manually
5. Total: 45+ minutes

**MicroRapid Approach**:
```bash
# 1. Init (10 seconds)
mrapids init k8s --from-url https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json

# 2. Test (immediate)
cd k8s
mrapids list | grep -i pod
mrapids run listNamespacedPod --param namespace=default

# Total: < 1 minute
```

### Developer Testimonial (Hypothetical):
> "I used to spend hours setting up API clients. With MicroRapid, I can test a new API in seconds. The OAuth flow that took me days to implement now works with one command." - DevOps Engineer

---

## 🚀 Summary

MicroRapid's philosophy: **"Your API, but executable"**

Instead of generating code, managing dependencies, and fighting with authentication, developers can:
1. **Execute immediately** - No setup, no code generation
2. **Debug visually** - See exactly what's happening
3. **Integrate everywhere** - It's just a CLI tool
4. **Authenticate simply** - OAuth made as easy as possible
5. **Work naturally** - Terminal-first, Unix-compatible

The tool doesn't try to be everything - it solves the 80% use case exceptionally well:
- ✅ Quick API testing
- ✅ CI/CD integration  
- ✅ Development workflows
- ✅ API exploration
- ✅ Debugging

This focused approach makes MicroRapid a **10x improvement** for common API tasks.