mockzilla 0.1.2 copy "mockzilla: ^0.1.2" to clipboard
mockzilla: ^0.1.2 copied to clipboard

A solution for configuring and running a local HTTP server as part of a Flutter app.

A Flutter plugin for running and configuring a local, mock HTTP server that allows your mobile app to simulate calls to a REST API.

Full documentation available here!

Why use Mockzilla? #

✅ Compile safe mock endpoint definitions.

✅ HTTP client agnostic.

✅ Works completely offline.

✅ Entirely self-contained in your application's codebase.

To hit the ground running #

Before we begin: Mockzilla is a development tool only. Do not use it in production! Advice on how to do this using different Dart entrypoints can be found here.

(1) Create your Mockzilla server config and add mocked endpoints.

final mockzillaConfig = MockzillaConfig().addEndpoint(
    () => EndpointConfig(
        name: "Hello world",
        endpointMatcher: (request) => request.uri.endsWith("/hello-world"),
        defaultHandler: (request) => const MockzillaHttpResponse(
            body: jsonEncode(const HelloWorldResponse())),
        ),
        errorHandler: (request) => const MockzillaHttpResponse(
            statusCode: 418,
        ),
    ),
);

(2) Start the mock server!

// Make sure to call this before starting Mockzilla!
WidgetsFlutterBinding.ensureInitialized();

await Mockzilla.startMockzilla(mockzillaConfig);