Skip to content

Get started with endpoints

This page will help you get started with creating an extension that uses endpoints. It describes how to generate the boilerplate code for an extension with an endpoint, 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.

Create your endpoint

  1. To get started, run the following command to create a new extension:

    npm create @netlify/sdk@latest
  2. Then, follow the prompts to add the Build Event Handler or Extension UI boilerplate.

    The Netlify SDK will scaffold the basic structure needed for your extension which includes these required files:

    • src/index.ts
    • package.json

    The src/index.ts file is the entrypoint for your extension and is listed in the main property of your package.json.

  3. Create a file at src/endpoints/my-function.ts and create your first endpoint:

    src/endpoints/my-function.ts
    import { withNetlifySDKContext } from "@netlify/sdk/ui/functions";
    export default withNetlifySDKContext((req, context) => {
    const { client } = context;
    // Add your logic here
    return Response.json({});
    });

Develop your endpoint

Now that you’ve added an endpoint to your extension, you can tailor it to fit your needs.

If your endpoint makes calls to a third-party API that requires authentication, you can configure your extension 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

Endpoints do not support Scheduled Functions or Background Functions.

Build your endpoint

Once you’re done developing your endpoint, you can compile your code by using the following Netlify SDK command:

pnpm run build

The code is compiled to the .netlify directory. These functions are deployed and hosted by Netlify when you publish your extension, you don’t need to deploy these functions separately once they’re built.

Next steps

Got it!

Your feedback helps us improve our docs.