This repository showcases a project integrating Azure Functions with a PostgreSQL database using Python. It provides a suite of API endpoints to manage a list of people, demonstrating the deployment and execution of serverless functions with database connectivity on Azure.
To successfully run this project, ensure you have the following:
- Knowledge of basic API concepts
- An active Azure subscription
- Azure CLI version 2.4 or later
- Docker
- Azure Functions Core Tools
- Azure Functions extension for VS Code
- Python 3 (preferably 3.11.xx)
You will need the following configuration files:
.envin the project root for Docker.envin thefrontendfolderlocal.settings.jsonin theapifolder for Azure Functions
Sample configuration files are included in the repository.
Follow these steps to set up and run the project:
-
Clone the Repository
git clone <repository_url> cd <repository_folder>
-
Start the PostgreSQL Database
In the project root, execute:
docker-compose up
Customize the database credentials in the
docker-compose.ymlfile or directly via the.envfile.For Linux users:
Create a
pgdatadirectory in the project root:mkdir pgdata
Change the permissions and set the user and group of the
pgdatadirectory to 1001:sudo chown -R 1001:1001 pgdata
-
Set Up Azure Functions
Create a Python virtual environment in the project root and activate it:
python3 -m venv ./venv source ./venv/bin/activate -
Install Python Dependencies
From the project root, run:
python3 -m pip install -r requirements.txt
-
Deploy and Run Azure Functions
For the initial setup, deploy the functions to Azure by following these steps:
-
Press
Fn + F5to deploy the functions, or run the following command in the terminal:func start
-
Follow the prompts to configure and debug the functions locally.
-
-
Access the Application
Open a browser and navigate to
http://localhost:7071/api/helloto see the message "Hello, World!".
The following API endpoints are available:
- add_people: [GET]
http://localhost:7071/api/add_people - add_test_user: [GET]
http://localhost:7071/api/add_test_user - delete_people: [DELETE]
http://localhost:7071/api/drop_people - get_people: [GET]
http://localhost:7071/api/people - hello: [GET, POST]
http://localhost:7071/api/hello - validate_user: [POST]
http://localhost:7071/api/validate_user - add_user: [POST]
http://localhost:7071/api/add_user
- Use Postman or another API testing tool to test the endpoints.
- Send a [POST] request with your name to the
/api/helloendpoint to verify functionality. - Use the "Populate Data" button to insert five people's sample data into the database.
- Use the "Delete Data" button to remove the data.
- Use the "View Data" button to view the data.
A Postman collection is available for testing the API endpoints:
This guide outlines the steps to clone the repository, set up the PostgreSQL database, configure Azure Functions, and access the API endpoints for testing and usage.