This project is a local mock server that uses a YAML file to define routes, methods, and responses. The server automatically restarts if the YAML file is modified.
- Dart SDK
-
Clone this repository:
git clone <REPOSITORY_URL> cd <DIRECTORY_NAME>
-
Install the dependencies:
dart pub get
To start the server, use the following command:
dart run bin/local_mock_apirest.dart --port <PORT> --path <PATH_TO_YAML_FILE>
For example:
dart run bin/local_mock_apirest.dart --port 8080 --path ./mock.yaml
The YAML file should have the following structure:
routes:
- path: "/"
method: "GET"
response:
status: 200
body: "Hello, world!"
time: 1000
headers:
- key: "Content-Type"
value: "text/plain"
- path: "/api"
method: "POST"
response:
status: 201
body: "{\"message\": \"Created\"}"
time: 2000
headers:
- key: "Content-Type"
value: "application/json"
- path: "/error"
method: "GET"
response:
status: 500
body: "{\"message\": \"Internal Server Error\"}"
time: 3000
headers:
- key: "Content-Type"
value: "application/json"
The server monitors the specified YAML file for changes. If the file is modified, the server stops and restarts automatically to load the new routes and responses.
The server will automatically stop and restart when the YAML file is changed. If you want to stop the server manually, you can do so by pressing Ctrl+C
in the terminal.
This project includes unit tests to validate the server's behavior and the YAML file's validity.
To run the tests, use the following command:
dart test
bin/local_mock_apirest.dart
: Server entry point.lib/local_mock_apirest.dart
: Main server logic.test/server_test.dart
: Unit tests for the server.test/mock.yaml
: Test YAML file.
Contributions are welcome. Please open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE
file for details.