Aryan3212
Aryan3212

Reputation: 97

Can the Astro Static Site Generator framework be used to create pages on the fly from data fetched from an API?

A project in our company was built using Astro and Svelte. In this project, API calls have to be made to a CMS to create blog posts dynamically. I would like a way for my clients to write blog posts, update the CMS(GraphCMS) and see that the website has created a new post.

Upvotes: 3

Views: 5029

Answers (2)

endymion1818
endymion1818

Reputation: 485

There are 2 ways this can be done.

GraphCMS allows you to fire a web hook when an action is completed, in this case publish a blog post. You need to be hosting on something like Vercel or Netlify, but as long as your build system has a web hook trigger, it can accept the payload and rebuild the site. It'll take a minute or two to complete, but the person should be able to see the new content relatively quickly.

The other way, as other authors have suggested, is to use Astro with Svelte, React or some other client-side JS, and add a client-side router which can then fetch and render posts on the client. That's less efficient because your users will have to wait for data to be fetched, and it probably won't show up in search engines.

Upvotes: 2

Related Questions