title | description | services | author | ms.service | ms.topic | ms.date | ms.author |
---|---|---|---|---|---|---|---|
API support in Azure Static Web Apps with Azure Functions |
Learn what API features Azure Static Web Apps supports |
static-web-apps |
craigshoemaker |
static-web-apps |
conceptual |
03/29/2022 |
cshoe |
Azure Static Web Apps provides serverless API endpoints via Azure Functions. By using Azure Functions, APIs dynamically scale based on demand, and include the following features:
-
Integrated security with direct access to user authentication and role-based authorization data.
-
Seamless routing that makes the api route available to the web app securely without requiring custom CORS rules.
Azure Static Web Apps APIs are supported by two possible configurations depending on the hosting plan:
-
Managed functions: By default, the API of a static web app is an Azure Functions application managed and deployed by Azure Static Web Apps associated with some restrictions.
-
Bring your own functions: Optionally, you can provide an existing Azure Functions application of any plan type, which is accompanied by all the features of Azure Functions. With this configuration, you're responsible to handle a separate deployment for the Functions app.
The following table contrasts the differences between using managed and existing functions.
Feature | Managed Functions | Bring your own Functions |
---|---|---|
Access to Azure Functions triggers | Http only | All |
Supported Azure Functions runtimes1 | Node.js 12 Node.js 14 Node.js 16 .NET Core 3.1 .NET 6.0 Python 3.8 Python 3.9 |
All |
Supported Azure Functions hosting plans | Consumption | Consumption Premium Dedicated |
Integrated security with direct access to user authentication and role-based authorization data | ✔ | ✔ |
Routing integration that makes the api route available to the web app securely without requiring custom CORS rules. | ✔ | ✔ |
Durable Functions programming model | ✕ | ✔ |
Managed identity | ✕ | ✔ |
Azure App Service Authentication and Authorization token management | ✕ | ✔ |
API functions available outside Azure Static Web Apps | ✕ | ✔ |
Key Vault references | ✕ | ✔ |
1 To specify the runtime version in managed functions, add a configuration file to your frontend app and set the apiRuntime
property. Support is subject to the Azure Functions language runtime support policy.
API endpoints are available to the web app through the api route.
Managed functions | Bring your own functions |
---|---|
While the api route is fixed, you have control over the source code folder location of the managed functions app. You can change this location by editing the workflow YAML file located in your repository's .github/workflows folder. | Requests to the api route are sent to your existing Azure Functions app. |
Logs are only available if you add Application Insights.
Managed functions | Bring your own functions |
---|---|
Turn on logging by enabling Application Insights on your static web app. | Turn on logging by enabling Application Insights on your Azure Functions app. |
- The API route prefix must be api.
- Route rules for API functions only support redirects and securing routes with roles.
Managed functions | Bring your own functions |
---|---|
|
|
[!div class="nextstepaction"] Add an API