/ justapi / tests / test_annotations.py
swadhinbiswas test: add end-to-end integration test suite with gRPC and proto stubs · 7/9/2026
43e015f
27 lines · 741 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
import threading
import time
import urllib.request
from justapi import JustAPIApp, Path, Query, Header, JSONResponse

app = JustAPIApp()

@app.get("/hello/{name}")
def hello(name: str = Path(), count: int = Query(1), x_token: str = Header(alias="X-Token", default="abc")):
    return JSONResponse({
        "name": name,
        "count": count,
        "token": x_token,
    })

def run_server():
    app.run("127.0.0.1:8083")

if __name__ == "__main__":
    t = threading.Thread(target=run_server, daemon=True)
    t.start()
    time.sleep(1)

    req = urllib.request.Request("http://127.0.0.1:8083/hello/world?count=5", headers={"X-Token": "xyz"})
    with urllib.request.urlopen(req) as response:
        print(response.read().decode())