Skip to content

Why You Should Always Specify IDs in Stubs ​

Explicitly defining UUID-based IDs in your stub configurations unlocks powerful capabilities in GripMock, from precise stub management to seamless developer workflows. Here's why IDs are essential:

1. Universal Identification πŸ” ​

Every stub MUST have a UUIDv4 identifier:

yaml
- id: 7f746310-a470-43dc-9eeb-355dff50d2a9 # βœ… Valid UUIDv4  
  service: BookingService
  method: GetBooking
  input:
    equals:
      bookingId: "booking_123"
  output:
    data:
      bookingTime:
        startTime: "2024-01-01T00:00:00Z"
        endTime: "2024-01-01T23:59:59Z"
  • ❌ Don't use custom strings like my_stub_123
  • βœ… Generate with uuidgen or online tools

2. Admin Panel Efficiency πŸš€ ​

Instantly locate stubs in the web UI:

bash
# Open in your browser
http://localhost:4771/#/stubs/7f746310-a470-43dc-9eeb-355dff50d2a9/show

WARNING

Search by ID in the admin panel is not available yet; use the direct URL for now.

3. Dead Stub Detection 🧹 ​

Clean up abandoned stubs via API:

bash
# Find unused stubs  
curl http://localhost:4771/api/stubs/unused

# Delete if unused  
curl -X DELETE http://localhost:4771/api/stubs/7f746310-a470-43dc-9eeb-355dff50d2a9

4. Live Reloading Magic πŸ”„ ​

WARNING

Warning! If you do not specify IDs in your stubs, IDs may change when the file is updated.

Enable automatic updates without restarting GripMock:

bash
# .env configuration  
STUB_WATCHER_ENABLED=true # Default value: true
STUB_WATCHER_INTERVAL=5000ms # Default value: 1s.
STUB_WATCHER_TYPE=fsnotify # Filesystem events. Default value: fsnotify. Other options: timer.
  1. Edit stubs/feature_x.yaml in your IDE
  2. GripMock auto-updates only modified stubs
  3. No API calls or restarts needed

INFO

In timer mode, GripMock does not reload all stubs every N seconds. It reloads only files with updated modification times.

5. Collision Prevention ⚠️ ​

Unique IDs prevent conflicts in multi-team environments:

yaml
# Team A's stub  
- id: 6e8b4c2a-3d8f-4a1b-8c9d-0e7f2a9b8c7d  
  service: Payments  
  method: Process  

# Team B's stub  
- id: 9f1a2b3c-4d5e-6f7a-8b9c-0d1e2f3a4b5c  
  service: Payments  
  method: Refund

Key Implementation Rules πŸ“Œ ​

  • πŸ†” UUIDv4 required (no custom formats)
  • πŸ”„ Auto-reloading requires both:
    • id field in YAML/JSON
    • STUB_WATCHER_ENABLED=true
  • 🚫 Never reuse IDs across environments