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 non-negotiable:
1. Universal Identification ๐ โ
Every stub MUST have a UUIDv4 identifier:
- 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"
- โ Never use custom strings like
my_stub_123
- โ
Generates with
uuidgen
or online tools
2. Admin Panel Efficiency ๐ โ
Instantly locate stubs in the web UI:
# Open in your browser
http://localhost:4771/#/stubs/7f746310-a470-43dc-9eeb-355dff50d2a9/show
WARNING
Search by ID in the admin panel will be available later, but now you can only go to the direct URL
3. Dead Stub Detection ๐งน โ
Cleanup abandoned stubs via API:
# 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 ID in stubs, then when you change the file, the ID may change. Keep this in mind.
Enable automatic updates without restarting GripMock:
# .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.
- Edit
stubs/feature_x.yaml
in your IDE - GripMock auto-updates only modified stubs
- No API calls or restarts needed
INFO
In timer mode, GripMock will not stupidly unload and load all the stabilizers from the file system every N seconds. Only files with a changed modification time will be transferred.
5. Collision Prevention โ ๏ธ โ
Unique IDs prevent conflicts in multi-team environments:
# 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/JSONSTUB_WATCHER_ENABLED=true
- ๐ซ Never reuse IDs across environments