API endpoints over uplink / server reloads

Server side functions by default are reloaded when called, each and every time.

Is the same true for API endpoints?

If it is, would hosting the endpoint code over uplink speed things up, or would the realoading of the “endpoint bit” negate any benefit? Would checking the persistent server checkbox help here?

I obviously have to find a way to test this, but some insight into the reloading thing would be useful.

Good question! Yes, the same is true for API endpoints, and enabling persistent server will avoid this, as it does for @callable functions.

Hosting the endpoint on the Uplink is indeed another way to avoid the reload, but you will need to balance that against the overhead of calling out of Anvil to your script. If the script is running on a Raspberry Pi in your basement, that could take some time. If it’s in the AWS London region, it’s likely to be negligible!

4 Likes

Thanks, @daviesian. The uplink would be at Linode or DigitalOcean in London, so sounds like it should be pretty quick.

So if I decorate my uplink server function as an endpoint, no portion of the chain Remote API Call → Anvil → Uplink needs to be reloaded on each call with persistent server disabled, is that right? The only overhead is the call from Anvil to my server?

Correct. At least, it will be equivalent to running with Persistent Server enabled (because we always need to load some parts of your app in order to route the call. We just don’t need to run your Server Module code).

One thing to bear in mind: If your Uplink is disconnected for any reason, incoming calls will be routed into your server code (in case they can be served by a @callable function there), which will need to be reloaded every time. So failures might be rather slower than you would otherwise expect.

3 Likes

So endpoints in this scenario work the same as regular callables, in that the uplink code takes priority but server side can be used as a fallback (in this case I would return a simple “something is wrong” response).

Interesting, thanks.

1 Like

Correct again! Endpoints are exactly equivalent to callables throughout the platform. In fact, they’re just a (namespaced) callable function - no more, no less!

3 Likes

I had no idea it did this, good to know!

1 Like

It’s a really useful feature. I tend to dummy up the backend with server side code that writes to local storage. That allows me to get the front end right, then as I write the uplink code I replace the server code with “something has gone wrong” responses, logs and often an email to tell me what’s happened.

3 Likes