Fetching from builder serverless function, within an edge function

Hi there! I’m really enjoying playing around with Edge Functions. So much potential!

I’m trying to work with a rate-limited API, which only allows around 500 requests per month on the free plan. It’s a sports stats API that I’m using to get the next game when Carlos Alcaraz is playing.

Because edge function responses can’t be cached with a TTL, I was wondering if this approach is possible:

  • create a regular serverless function to get data from the rate-limited API with on-demand builders, with a TTL of 3600. (eg. when-is-alcaraz-playing.netlify.app/next-game-data.json)
  • create an edge function that fetches from the URL above. Most of the time it’ll be fetching a cached response.

If this is possible, I’ll be able to customise the edge function response based on the user’s timezone. I’ll also be able to relative times (eg. the game started 1 hour ago). I can’t do that if I just use the cached serverless function response by itself.

I’m keen to know if there are limitations about fetching from one edge function to a serverless function within a site, or if it behaves just like a regular fetch.

Thanks!

Hey! This is a great pattern, and one we recommend. It also has the benefit of caching the response in the CDN, local to the edge function.

Awesome, thank you for confirming. Will keep experimenting - the next challenge will be working out the user’s timezone based on the geo information!