This project demonstrates how to create a simple Azure Function to perform CRUD (Create, Read, Update, Delete) operations on a SQL database using HTTP triggers.
The project consists of an Azure Function called StockAPI
which provides an HTTP endpoint to create a new stock entry in the database. The function receives a JSON payload containing the details of the stock to be added, validates it, and then inserts the data into the SQL database.
The StockAPI
function has the following features:
- Create-Stock Endpoint: An HTTP POST endpoint (
Create-Stock
) is exposed to create a new stock entry. - Input Validation: The function validates the incoming payload to ensure it contains the necessary data.
- Database Interaction: The function interacts with a SQL database to insert the new stock entry.
Before running this Azure Function, ensure the following:
- Azure subscription
- Azure Function App created
- SQL Database provisioned
- Connection string to the SQL Database available in the Azure Function environment variables
- Clone this repository to your local machine.
- Configure the Azure Function App settings with the required connection string to the SQL Database.
- Deploy the Azure Function to your Azure Function App.
To use the Create-Stock
endpoint:
- Send an HTTP POST request to the endpoint URL with a JSON payload containing the details of the stock to be added.
- The function will validate the payload and insert the data into the SQL Database.
- Upon successful insertion, the function will return a 200 OK response with the details of the newly created stock entry.
Example payload:
{
"StockName": "Example Stock",
"Price": 10.5
}