/ justapi / benchmarks / workloads_native_query.py
swadhinbiswas WIP save-point: production hardening, H3 removal, fmt gate, and accumulated phase work · 7/15/2026
a293d8c
33 lines · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Benchmark: native query-param fast path (GET + query_schema + native=True).

Validates the query string in Rust and echoes parsed params as JSON, with no
GIL/Python hop. Mirrors the body fast path but for GET routes.
"""
from justapi import JustAPIApp

app = JustAPIApp()

QUERY_SCHEMA = {
    "type": "object",
    "properties": {
        "name": {"type": "string"},
        "age": {"type": "integer", "minimum": 0},
    },
    "required": ["name"],
}


@app.get("/search", native=True, query_schema=QUERY_SCHEMA)
def search():
    # Never runs on the fast path (request is validated + echoed in Rust).
    return {"echo": True}


@app.get("/search_gil")
def search_gil(name: str = "", age: int = 0):
    return {"name": name, "age": age}


if __name__ == "__main__":
    app.run("127.0.0.1:8263")