Primo REST API #325
mateomorris
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Primo v2--beta.17 introduces a the ability to consume your site content as a REST API directly from your Primo Server. Previously, to consume your site content from another source (like SvelteKit) you had to fetch the site file published with your site builds, but that's kind of hacky since it wasn't the original intention for the file (and the file could get pretty big for medium to larger sites).
You can access your content by fetching it from the '/api/' endpoint (e.g. https://try.primocms.org/api/theme-nonprofit). The response looks like this:
The properties within
site
,page
, andsections
represent field values set in your Site, Page, and the blocks on the page, respectively. Each includes a_meta
tag containing metadata about the site, each page, and each section, with which you could do things like: fetch each subpage under the 'blog' page individually (usingpage._meta.subpages
), access the header on the homepage by itsid
, or grab each section which is an instance of the 'content' symbol (usingsections._meta.symbol
).This is just a first pass at this, so expect it to change as it gets used and input is given by the community. Updates will be posted here and the Primo forum so you can track any breaking changes. I'm happy to hear how it could be improved as things come up; some things off the top of my head that I could see being needed in the future are:
Beta Was this translation helpful? Give feedback.
All reactions