Create REST API using Azure Function - HTTP Trigger
In this blog post, I have demonstrated how you can setup an environment and create a REST API using Azure Functions – HTTP Trigger Service.
Azure Function is a serverless, event driven compute service that lets you run pieces of code (called “functions”) without managing any servers or infrastructure.
How it works:
Triggers are something what cause the function to run.
Common Triggers:
- HTTP Request Trigger (like Web API call)
- Timer Trigger (for scheduled jobs)
- Event based Trigger (like something happen on Blob Storage or message queue)
Key Benefits of Azure Functions
- No Infrastructure Management
- Automatic Scaling
- Pay-as-you-go pricing
- Multiple codding language support – C#, Python, Java, JavaScript, PowerShell etc.
Common Use Cases
- Building lightweight REST APIs & Webhooks
- Processing file upload or resizing images when added to storage
- Running scheduled cleanup tasks or background jobs
Complete Tutorial Video
Follow the below steps
https://lastminutecoders.in/wp-content/uploads/2026/10/resources.zipStep 1: Install 3 Tools using Command Prompt
- winget install Python.Python.3.12
- winget install Microsoft.VisualStudioCode
- winget install Microsoft.Azure.FunctionsCoreTools
Check, the python version and Azure function core tools version
- python –version
- func –version
Step 2: Install following Extension within Visual Studio Code
Press: Ctrl+Shift+X (Then automatically search for following extension)
- Azure Functions (By Microsoft)
- Python (By Microsoft)
- Azurite (By Microsoft)
Note: For Azure Functions – You need to install Active Azure Subscription (https://azure.microsoft.com/en-us/pricing/purchase-options/azure-account)
Step 3: We have to create new Azure function project in Visual Studio Code
- First create a folder (product-api) in your System.
- With VS Code -> Press F1 -> Search -> Azure Functions: Create New Project
- Now you have to update following files:
- function_app.py
- host.json
- requirements.txt
- local.settings.json
Kindly download the below zip file and extract it – All the files related to the project will be available there
- In VS Code Terminal – Run this commands
pip install -r requirements.txt
Step 4: To create local server in your system, we need to start Azurite
- Press F1 -> search -> Azurite: Start
This emulates Azure storage on our local machine - In VS Code terminal, run following command
– func start - Create a body.json file in your project folder (body.json file will be available in resources zip)
- Now to test you API locally, you have to run following commands
- Create New Product command: curl.exe -X POST https://localhost:7071/api/products – H “content-Type:application/json” -d “@body.json”
- Get All Products command: curl.exe -X GET https://localhost:7071/api/products
- Get Product by ID command: curl.exe -X GET https://localhost:7071/api/products/{id}
- Update Product by ID command: curl.exe -X PUT https://localhost:7071/api/products/{id} – H “content-Type:application/json” -d “@body.json”
- Delete Product by ID command: curl.exe -X DELETE https://localhost:7071/api/products/{id}
Step 5: Create the Function App in Azure
Go to Azure Portal -> Create Function App -> Select Flex Consumption as Hosting Plan and fill other details as shown in video
Step 6: Deploy and Configure
- Open VS Code in Terminal run following command: func azure funcitonapp publish {function-app-name}
- Get the storage Connection string: Portal -> Storage Account -> Security + Networking -> Access Keys -> Copy Connection string
- Now go to Function App -> Settings -> Environment Variable -> Create New -> “TABLE_CONNECTION_STRING” -> Apply & Confirm
- Finally get your API key from Function App -> API Keys -> Copy the default host key.
Step 7: Testing the API – Open Powershell in Windows
$base = “https://{function-app-link}/api”
$headers = @{“x-functions-key”=”{YOUR API KEY}”}
- Create New Product command: $created = Invoke-RestMethod -Method Post -Uri “$base/products” -Headers $headers -ContentType “application/json” -Body ‘{“name”:”Laptop”, “price”:50000, “category”:”Electronics”}’
- Get the Created product ID: $id=$created.id
- Get All Products command: Invoke-RestMethod -Method Get -Uri “$base/products” -Headers $headers
- Get Product by ID command: Invoke-RestMethod -Method Get -Uri “$base/products/$id” -Headers $headers
- Update Product by ID command: Invoke-RestMethod -Method Get -Uri “$base/products/$id” -Headers $headers -ContentType “application/json” -Body ‘{“name”:”Laptop NEW”, “price”:50000, “category”:”Electronics”}’
- Delete Product by ID command: Invoke-RestMethod -Method Delete -Uri “$base/products/$id” -Headers $headers