Before you run#
Use an installed, authenticated Yak CLI with access to the invite-only preview. Read Live Apps for the full setup and current behavior.
Python example
Declare GET and POST endpoints for a Live App.
Use an installed, authenticated Yak CLI with access to the invite-only preview. Read Live Apps for the full setup and current behavior.
import asyncio
import yak
app = yak.App(name="hello-live-app")
@app.task()
@yak.web_endpoint(method="GET", path="/hello")
def hello(request: yak.Request) -> yak.Response:
name = request.query_params.get("name", "Yak")
return yak.Response(
body={"message": f"hello from {name}", "path": request.path},
status=200,
)
@app.task()
@yak.web_endpoint(method="POST", path="/echo")
def echo(request: yak.Request) -> yak.Response:
payload = request.json
return yak.Response(
body={"received": payload},
status=200,
)
@app.entrypoint()
async def main() -> None:
await app.serve()
if __name__ == "__main__":
asyncio.run(main())
Save the source as hello_live_app.py, then run:
$ yak serve hello_live_app.py