Get started with API Handlers
This page will help you get started with creating an integration that uses API Handlers. It describes how to generate the boilerplate code for an integration with an API handler, what the required files and basic scaffolding are, and how to build your code.
Prerequisites
Windows users should run the Netlify SDK through WSL 2
Support for using the Netlify SDK on Windows is currently only available through WSL 2.
- Node.js 18 or later
- Netlify CLI
- TypeScript
Create your API handler
-
To get started, run the following command to create a new integration:
-
Then, follow the prompts to add the
Build Event Handler
orIntegration UI
boilerplate.The Netlify SDK will scaffold the basic structure needed for your integration which includes these required files:
src/index.ts
package.json
The
src/index.ts
file is the entrypoint for your integration and is listed in themain
property of yourpackage.json
. -
Inside the
src/index.ts
file, declare an instance ofNetlifyIntegration
and call the methodaddApiHandler
to create your first API handler.
Develop your API handler
Now that you’ve added an API Handlers component to your integration, you can tailor it to fit your needs.
- Use values and methods to develop the logic for your API handler.
- Debug and test your API handler to make sure it works as expected.
If your API handler makes calls to a third-party API that requires authentication, you can configure your integration to allow users to authenticate through an OAuth identity provider. Once a user authenticates, you can access the OAuth token and use it to make requests on the user’s behalf.
Synchronous serverless functions only
API handlers do not support Scheduled Functions or Background Functions.
Build your API handler
Once you’re done developing your API handler, you can compile your code by using the following Netlify SDK utility tools command:
The code is compiled to the folder .ntli
. These functions are deployed and hosted by Netlify when you publish your integration, you don’t need to deploy these functions separately once they’re built.
Next steps
- Call your API handler from a build event handler or an integration’s UI.
- Configure your integration to allow users to authenticate with an OAuth identity provider.
- Learn how to publish your integration when you’re ready to share it with users.