Gatsby – APIs
In this section, we are going to explore how to use APIs inside Gatsby. In the example that we will build in this chapter, we will create an event form whereby anonymous users can propose their event. When the user submits the form, we will add the submission to Sanity via an API.
To achieve this, we will do the following:
- Create a Netlify form on the home page of our events application.
- Configure a token from Sanity so that we can submit the form via an API.
- Configure a Netlify function to send data on submission.
Creating a Netlify form
As our third-party service, we will use Netlify Forms, a built-in form-handling functionality provided by Netlify. When the code is deployed to Netlify, the system automatically detects the form and creates a form submission page in your Netlify site's admin panel.
To create a Netlify form, simply add the netlify="true"
attribute data to the <form>
tag, add the <input type...