Migrate HTTP functions to HTTP endpoints in your new Wix CLI project, as part of migrating an app from the legacy Wix CLI.
| Legacy path | New path |
|---|---|
src/backend/api/<name>/api.ts | src/api/<name>.ts |
src/backend/<sharedModule>.ts | src/lib/<sharedModule>.ts |
src/backend/api/<name>/api.ts to src/api/<name>.ts in your new Wix CLI project.src/lib/ in the new project. Shared modules aren't extensions, so they don't belong under src/api/.In src/api/<name>.ts:
Add the APIRoute type import:
Change method signatures from:
To:
Then rename every req in the handler's body to request.
If the handler never uses req, drop the parameter instead:
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.
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:
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:
To:
The following example shows the old HTTP functions syntax from your legacy project, with files located in the src/backend/api/ directory:
The following example shows the new HTTP endpoints syntax in your new Wix CLI project, with files located in the src/api/ directory:
Last updated: 10 November 2026