This repository includes a very simple Python FastAPI HTTP API, made for demonstration purposes only.
- Open this repository in Github Codespaces or VS Code with Remote Dev Containers extension.
- Open the Terminal and navigate to the
api
directory.
cd api
- Use uvicorn to run the FastAPI app:
uvicorn main:app --reload --port=8000
- Click 'http://127.0.0.1:8000' in the terminal, which should open the website in a new tab.
- Append
/generate_name
to the end of the URL.
Since this project is designed to be deployed to Azure Functions,
you can also use the local emulator from Azure Functions Core Tools
to test the function locally.
- Open this repository in Github Codespaces or VS Code with Remote Devcontainers extension.
- Open the Terminal and make sure you're in the root folder (
simple-fastapi-azure-function
). - Run
func host start
- Click 'http://localhost:7071/{*route}' in the terminal, which should open the website in a new tab.
- Change the URL to navigate to either the API at
/generate_name
or the docs at/docs
.
This repo is set up for deployment to Azure Functions plus Azure API Management,
using azure.yaml
and the configuration files in the infra
folder.
Steps for deployment:
-
Sign up for a free Azure account
-
Install the Azure Developer CLI. (If you open this repository in Codespaces or with the VS Code Dev Containers extension, that part will be done for you.)
-
Navigate back to the root folder (the one with
azure.yaml
) if you're not already there. -
Login to Azure:
azd auth login
-
Provision and deploy all the resources:
azd up
It will prompt you to provide an
azd
environment name (like "django-app"), select a subscription from your Azure account, and select a location (like "eastus"). Then it will provision the resources in your account and deploy the latest code. -
Once it finishes deploying, find the endpoint URL in the terminal and navigate to that URL, appending either
/generate_name
or/docs
. -
When you've made any changes to the app code, you can just run:
azd deploy