Skip to main content

4. Start the API Server

4.1 Azure Functions Core Tools

While not mandatory, your application may choose to take advantage of serverless API support with Azure Functions. Azure Functions service has its own Azure Functions Core Tools CLI to support local development. Read the API Reference to learn about its func command and options.

By using the SWA CLI, we can streamline the local development workflow (across Azure Static Web Apps and Azure Functions) even further. The SWA CLI can:

  • verify that Azure Functions Core Tools is installed in your local development environment.
  • download or update the right version for you if needed.
  • give you the flexibility to have the CLI manage the API server launch if needed.

Let's explore these options.

4.2 Start API Server Manually

You might want to run the Azure Functions Core Tools (API server) separately, to take advantage of built-in features like debugging and rich editor support.

To use the SWA emulator services alongside the API server:

  1. Start API server first using Azure Functions Core Tools CLI (below) or the VS Code Extension. Note the URL for the local API server, once it is running.
func host start
  1. Start SWA CLI in a separate terminal and use the --api-location option to pass it the relevant local API Server URI. For example:
swa start ./my-dist --api-location http://localhost:7071

4.3 Start API Server Automatically

This assumes you have previously created (and tested) an Azure Functions App project that is now located in an api folder in your local development environment.

  1. Launch the API server alongside the SWA emulator
swa start ./my-dist --api-location ./api
  1. Combine the launch with usage of a running dev server
swa start http://localhost:3000 --api-location ./api