local_mock_apirest 1.0.0 copy "local_mock_apirest: ^1.0.0" to clipboard
local_mock_apirest: ^1.0.0 copied to clipboard

A local mock server that uses YAML files to define routes, methods, and responses with automatic restart on file changes.

Local Mock API REST #

A local mock server that uses YAML files to define routes, methods, and responses. The server automatically restarts if the YAML file is modified.

Installation #

To install the package globally and use it as a command-line tool:

dart pub global activate local_mock_apirest

Requirements #

  • Dart SDK ^3.4.4

Usage #

Run the Server #

To start the server, use the following command:

local_mock_apirest --port <PORT> --path <PATH_TO_YAML_FILE>

For example:

local_mock_apirest --port 8080 --path ./mock.yaml

YAML File #

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"

Automatic Restart #

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.

Stop the Server #

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.

Contributions #

Contributions are welcome. Please open an issue or submit a pull request.

License #

This project is licensed under the MIT License. See the LICENSE file for details.

3
likes
140
points
9
downloads

Publisher

unverified uploader

Weekly Downloads

A local mock server that uses YAML files to define routes, methods, and responses with automatic restart on file changes.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

args, json_schema, shelf, yaml

More

Packages that depend on local_mock_apirest