Migrate from HTTP Functions to HTTP Endpoints

Migrate HTTP functions to HTTP endpoints in your new Wix CLI project, as part of migrating an app from the legacy Wix CLI.

Folder structure

Legacy pathNew path
src/backend/api/<name>/api.tssrc/api/<name>.ts
src/backend/<sharedModule>.tssrc/lib/<sharedModule>.ts

Step 1 | Copy and rename the file

  1. From your legacy project, copy src/backend/api/<name>/api.ts to src/api/<name>.ts in your new Wix CLI project.
  2. If the function imports shared backend modules, copy those modules into src/lib/ in the new project. Shared modules aren't extensions, so they don't belong under src/api/.

Step 2 | Adapt the code to the new project

In src/api/<name>.ts:

  1. Add the APIRoute type import:

    Copy
  2. Change method signatures from:

    Copy

    To:

    Copy

    Then rename every req in the handler's body to request.

    If the handler never uses req, drop the parameter instead:

    Copy
  3. Update the imports of shared backend modules to their new location. The file moved from src/backend/api/<name>/ to src/api/, and the modules moved to src/lib/. For example, ../../spotlight-store becomes ../lib/spotlight-store.

  4. Make sure that every path through the handler returns a Response. The APIRoute type requires it, so the typecheck fails with Type '...' is not assignable to type 'APIRoute' for a handler that returns anything else on some path, for example a plain object on an error path. Wrap such values in a Response:

    Copy

Update your frontend call sites as you migrate each extension

Copying the file and adapting its code moves your backend code. Your frontend call sites stay in the legacy project until you migrate the extension that holds them, so there's nothing to change here yet.

Come back to this section from Add the extension to the new project in the main migration guide, once the extension's code is in the new project. Then update its calls to point at the new endpoint:

Change from:

Copy

To:

Copy

Backend example

Previous syntax

The following example shows the old HTTP functions syntax from your legacy project, with files located in the src/backend/api/ directory:

Copy

Updated syntax

The following example shows the new HTTP endpoints syntax in your new Wix CLI project, with files located in the src/api/ directory:

Copy

Last updated: 10 November 2026

Did this help?