Yep, it’s here. Respond to any path within your app’s domain with @anvil.server.route
:
@anvil.server.route("/hello")
def hello(**p):
return {"hello":"world"}
$ curl https://my-interesting-app.anvil.app/hello
{"hello":"world"}
But wait - there’s more!
What if you don’t just want to serve a machine-readable response? What if you want to serve a human-accessible UI on a particular URL instead?
Just return a FormResponse
object:
@anvil.server.route("/my-page")
def my_page(**p):
return anvil.server.FormResponse("Form2")
You can even pass arguments into your forms - and yes, that includes data tables, portable classes and Media! For example:
@anvil.server.route("/users/:email")
def serve_user_page(email, **p):
user = app_tables.users.get(email=email)
if user:
return anvil.server.FormResponse('UserPage', user=user)
else:
return anvil.server.HttpResponse(404, "No such user")
Is that the sound of loading an entire page at once and rendering it in one go? Yes, I think it is.
Docs
Check out the new additions to our HTTP API documentation:
Watch this space
I would describe this particular feature as a “building block” release. We’re aiming for a world where multi-page, multi-URL apps with Anvil are easy for anyone to build. This API on its own doesn’t take us all the way there - but “perfect” is the enemy of “done”, so we’re putting it out there for you to use right away!