Skip to main content

serve_dynamic_mock

Function serve_dynamic_mock 

Source
pub async fn serve_dynamic_mock(
    state: &ManagementState,
    req: Request<Body>,
) -> Option<Response>
Expand description

Match an incoming request against mocks registered via the POST /__mockforge/api/mocks endpoint and return the first match’s response (ordered by descending priority). Returns None if nothing matches, so the caller can chain it with its existing 404.

This is what lets the @mockforge-dev/sdk Node.js SDK register a stub dynamically and have subsequent HTTP requests actually hit it — without it, stubs live in ManagementState but no route dispatches to them, so every SDK test would 404.