flutter_mock_server 0.1.2
flutter_mock_server: ^0.1.2 copied to clipboard
A Flutter-focused local mock API server with a YAML-driven CLI and hot reload.
flutter_mock_server #
A Flutter-focused local mock API server that reads routes from mock.yaml and serves predictable responses for app development.
Features #
flutter_mock initcreates a startermock.yamlanddata/folder.flutter_mock startruns a local server onhttp://localhost:8080by default.flutter_mock validatechecks YAML syntax and schema.- Supports
GET,POST,PUT, andDELETEroutes. - Serves inline bodies or JSON payloads from files.
- Expands template fields such as
{{uuid}},{{name}}, and{{timestamp}}. - Supports optional delays and probabilistic error responses.
- Reloads configuration automatically when
mock.yamlchanges.
Installation #
dart pub global activate flutter_mock_server
Or run it directly from the package:
dart run flutter_mock_server start
Commands #
Initialize a project #
flutter_mock init
Start the server #
flutter_mock start
Options:
--config Path to the YAML config file. Defaults to mock.yaml.
--host Host interface to bind. Defaults to localhost.
--port Port to bind. Defaults to 8080.
Validate configuration #
flutter_mock validate
Configuration #
Basic route configuration:
routes:
- path: /users
method: GET
response:
file: data/users.json
- path: /users
method: POST
response:
status: 201
body:
message: User created
id: "{{uuid}}"
Advanced response options:
routes:
- path: /users
method: GET
response:
delay_ms: 250
headers:
x-mock-source: flutter_mock_server
file: data/users.json
error:
rate: 0.2
status: 503
body:
message: Temporary mock failure
retryAt: "{{timestamp}}"
Supported template fields:
{{uuid}}{{name}}{{timestamp}}
Development #
dart pub get
dart analyze
dart run flutter_mock_server validate
dart run flutter_mock_server start
Example #
Run the end-to-end example:
dart run example/flutter_mock_server_example.dart
The example:
- creates a temporary project with
mock.yamlanddata/orders.json - starts
FlutterMockServeron a free local port - sends
GET /ordersandPOST /ordersrequests - updates
mock.yamlduring runtime to demonstrate hot reload
Package layout #
flutter_mock_server/
├── bin/flutter_mock.dart
├── bin/flutter_mock_server.dart
├── lib/cli/
├── lib/config/yaml_parser.dart
├── lib/server/
├── lib/utils/template_engine.dart
├── example/
├── mock.yaml
├── data/
├── pubspec.yaml
└── README.md