oliverdavies.uk/source/_daily_emails/2023-02-08.md

16 lines
1 KiB
Markdown
Raw Normal View History

2024-01-03 20:00:00 +00:00
---
title: >
2024-09-08 22:09:54 +00:00
Fetching external API data with Astro
2024-01-03 20:00:00 +00:00
pubDate: 2023-02-08
permalink: >-
daily/2023/02/08/fetching-api-data-with-astro
2024-01-03 20:00:00 +00:00
tags:
2024-09-08 22:09:54 +00:00
- astro
2024-01-03 20:00:00 +00:00
---
As well as using static data like Astro components and Markdown files, Astro allows you to pull in data from external APIs even if you're generating a static website.
Astro's [Data Fetching documentation](https://docs.astro.build/en/guides/data-fetching) shows how to do this using the global `fetch` function. This is the same approach that I've been using to build [a page of my open-source projects](https://github.com/opdavies/oliverdavies.uk/blob/39314de34ce22b14cf85f816e4469cc4d6fb822c/website/src/pages/open-source.astro). I'm still working on it, but it fetches project information from both Drupal.org and GitHub and displays them on a page.
This is also makes Astro a good option to be used as a front-end for decoupled projects that use a separate back-end CMS like Drupal to store and manage the content which it fetches and uses when generating the site.