DEV Community

nabbisen
nabbisen

Posted on

apimock-rs v4.3: Dynamic response generation support

API mock (apimock-rs) is a developer-friendly, featherlight and functional HTTP mock server built in Rust.

Docs: https://apimokka.github.io/apimock-rs/

We've rolled out its new minor version which brings upgrade on crafting responses. While the server has supported flexible routing for static responses based on file paths and rule sets, this update focuses on improving the Rhai middleware scripting.

The key improvement is that Rhai scripts now can dynamically generate response data. Previously, a script could only point to a static file path once a condition was met. Now, your scripts can directly create the response body, whether it's a JSON string or plain text. This means more powerful mocking capabilities with programmatically generated content for your development workflow.

let json_str = "{ \"greetings\": \"Hello, world.\" }";

// debug print:
print(url_path);

if url_path == "/middleware-test/map/json" {
    return #{ "json": json_str };
}
Enter fullscreen mode Exit fullscreen mode

We've also updated our documentation to guide you through these new features.

Top comments (0)