Path & Query Parameters¶
Mimicker supports dynamic path variables and query string matching out of the box.
Path parameters¶
Use {variable} syntax in the path. The variable is automatically injected into the response body wherever the same placeholder appears.
Multiple path parameters work the same way:
mimicker(8080).routes(
get("/orgs/{org}/repos/{repo}")
.status(200)
.body({"org": "{org}", "repo": "{repo}"})
)
Query parameters — explicit¶
Define query parameters directly in the path template. Only requests that include the exact parameter are matched.
Query parameters — implicit (wildcard)¶
When a path template has no query string, Mimicker matches any request to that path regardless of what query parameters are present. The parameters are still available in response_func via kwargs["query_params"].
mimicker(8080).routes(
get("/hello")
.status(200)
.body({"message": "Hello!"})
)
# GET /hello → 200 ✓
# GET /hello?name=bob → 200 ✓ (parameters ignored but available in response_func)
# GET /hello?x=1&y=2 → 200 ✓
Access implicit parameters in a dynamic response:
from typing import Dict, List
def greet(**kwargs):
query_params: Dict[str, List[str]] = kwargs["query_params"]
name = query_params.get("name", ["World"])[0]
return 200, {"message": f"Hello, {name}!"}
mimicker(8080).routes(
get("/hello").response_func(greet)
)
Query params are always lists
Because HTTP allows repeated parameters (?tag=a&tag=b), query_params values are always List[str]. Use [0] to get the first value.
Path params in response_func¶
Path variables are available as kwargs["params"]:
def user_detail(**kwargs):
user_id = kwargs["params"]["id"]
return 200, {"id": user_id, "name": f"User {user_id}"}
mimicker(8080).routes(
get("/users/{id}").response_func(user_detail)
)
Related¶
- Dynamic Responses — full
response_funcreference - Stubbing Guide