Server Query (@app.query)
Register a Python function as a JSON endpoint. It can be called from the browser without reloading.
python
from sistine import Sistine, el, fetch
app = Sistine()
@app.query
def get_cities():
return ["Jakarta", "Tokyo", "London", "New York"]
@app.query
def get_weather(city: str):
data = fetch(f"https://wttr.in/{city}?format=j1")
cc = data["current_condition"][0]
return {"temp": cc["temp_C"], "desc": cc["weatherDesc"][0]["value"]}ttl Parameter (Cache)
GET queries can be cached with ttl (in seconds):
python
@app.query(ttl=60)
def get_prices():
return fetch("https://api.example.com/prices")method Parameter
Methods other than GET will automatically bypass the cache:
python
@app.query(method="POST")
def create_user(data: dict):
return fetch("https://api.example.com/users", json_data=data)