Quickstart: Making HTTP requests
Integrate with third-party HTTP APIs
Anvil lets you make HTTP requests with very little code.
Follow this quickstart to access an external HTTP API from Python and print the response.
Create an app
Log in to Anvil and click ‘New Blank App’. Choose the Material Design theme.


Add a Server Module
In the App Browser, click the + next to Server Code to add a new Server Module.

You will see a code editor with a yellow background.

In the App Browser, click “+ Add Server Module” next to Server Code to add a new Server Module.

A new tab will open with a code editor with an orange background.

Write a server function
Write this function into the Server Module:
@anvil.server.callable
def access_xkcd_api(comic_number):
url = f"https://xkcd.com/{comic_number}/info.0.json"
response = anvil.http.request(url, json=True)
return response
anvil.http.request
makes the HTTP request. We are using the API of the webcomic XKCD to get
the details of a given comic.
Call your server function from the client
Go to the code for Form1. It looks like this:


At the end of the __init__
method, write these lines:
return_value = anvil.server.call('access_xkcd_api', 353)
print(return_value)
This means your function will run when the app starts, and the result will be printed.
Run your app
Now click the ‘Run’ button at the top of the screen.


The Output Panel should display this:


This is the data presented at https://xkcd.com/353/info.0.json
. It has automatically been converted to a Python dictionary
because we used json=True
in anvil.http.request
.
Copy the example app
Click on the button below to clone a finished version of this app into your account.
Next up
Want more depth on this subject?
Read more about HTTP APIs and requests in Anvil.
Want another quickstart?
Every quickstart is on the Quickstarts page.
Do you still have questions?
Our Community Forum is full of helpful information and Anvil experts.