You are currently viewing the new Anvil Editor Docs.
Switch to the Classic Editor Docs
You are currently viewing the Classic Editor Docs.
Switch to the new Anvil Editor Docs

HTTP APIs

You don’t need to make HTTP requests to build an Anvil app thanks to Anvil’s ability to call Python functions between client and server code (including code outside of Anvil). Even if you’re collaborating with a third-party, they can use the Client Uplink to safely make function calls to and from your app.

That said, HTTP is still a powerful tool to have available. Anvil has an HTTP requests library, plus a simple way to create HTTP endpoints that expose your app’s functionality over HTTP. Check the Quickstarts for this topic to get up and running.

Making HTTP Requests

Anvil has a human-friendly Python library for making HTTP requests. This works from client and server code.

import anvil.http
resp = anvil.http.request("https://api.mysite.com/foo")
print(f"Response MIME type: {resp.content_type}")

See Making HTTP Requests for details.

Creating HTTP APIs

You can make your server functions into HTTP endpoints using a decorator:

import anvil.server

@anvil.server.http_endpoint("/users/:id")
def get_user(id):
  ip = anvil.server.request.remote_address
  return f"You requested user {id} from IP {ip}"

See Creating HTTP Endpoints for details.


Do you still have questions?

Our Community Forum is full of helpful information and Anvil experts.