A demo repository for a blog post Providing next event as API with Eleventy’s Global Data Files and Netlify Functions.
This repository contains an Eleventy project that uses Netlify Functions for API access to global data.
In _data/
, we have events.json
with a few past and upcoming events. When we build the project, we create a Netlify Function (a serverless function) that returns that next event (or a different response if no events are scheduled for the future).
First, you need to install the dependencies
npm install
and install global Netlify CLI
npm install -g netlify-cli
Then run
netlify dev
to start a local development server that can run Netlify Functions.
Once running, you can call domain:8888/.netlify/functions/api which will return either
{
"status": "OK",
"data": { "date": "2025-05-20", "name": "May" }
}
where "status"
is always "OK"
. Event data has date in format YYYY-MM-DD
and name.
{
"status": "NO_EVENT_SCHEDULED",
"data": null
}
If no future events exist, "status"
will be "NO_EVENT_SCHEDULED"
and "data"
will be null
.