Changes in anvil.server.get_api_origin()

Hi @jamesmichaelhooker,

It looks like what you saw was a bug getting fixed, so sorry about that! The correct behaviour is that if you call get_app_origin() or get_api_origin() from an app in the Anvil editor, they’ll return a temporary development URL. If you’re running in the editor but you want to get the public URL of your app, call get_api_origin("published").

We’ve updated the docs to spell this out more clearly. Here’s the important part:

Sometimes you will want to generate URLs that point to your HTTP endpoints without having to hard-code the origin of your app. Instead of writing:

endpoint_url = "https://my-app.anvil.app/_/api/users"

You can call anvil.server.get_api_origin() :

endpoint_url = anvil.server.get_api_origin() + "/users"

This has the advantage of returning whichever origin the user is currently connected on, i.e. if you have published a version but you are running your development version in the Anvil editor, get_api_origin() will return a temporary private link to your development version, so you can test your APIs before publishing them!

If you’re running in the editor, get_api_origin() might return a URL that’s private or not permanent. To get the origin for the published version of your app, call get_api_origin('published') .

2 Likes