Skip to content

Commit 6007060

Browse files
committed
Add guide for creating a Simple Asset Management API with Azure Functions and related images
1 parent bb68dcf commit 6007060

8 files changed

Lines changed: 92 additions & 0 deletions
130 KB
Loading
70.7 KB
Loading
31.7 KB
Loading
102 KB
Loading
32 KB
Loading
56.9 KB
Loading
106 KB
Loading
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Creating a Simple Asset Management API with Azure Functions
2+
3+
This guide walks you through creating a simple mock API for an asset management application using Azure Functions. The API will expose a single operation to return a list of assets. You will also learn how to create a custom connector in Power Platform using API Management.
4+
5+
6+
7+
## Prerequisites
8+
- Azure account (a free plan is sufficient; you can use the [Azure Free Account](https://azure.microsoft.com/free/))
9+
- [VS Code](https://code.visualstudio.com/) (optional, but recommended)
10+
11+
## 1. Create a New Azure Function in the Azure Portal
12+
13+
1. Go to the [Azure Portal](https://portal.azure.com/).
14+
2. Click **Create a resource** > **Web** > **Function App**.
15+
3. Select **Consumption**.
16+
4. Fill in the required details:
17+
- **Subscription**: Select your subscription.
18+
- **Resource Group**: Create a new one or use an existing one.
19+
- **Function App name**: Choose a unique name.
20+
- **Runtime stack**: Node.js
21+
- **Region**: Choose a region close to you.
22+
5. Click **Review + create** and then **Create**.
23+
24+
![Create Function in Azure](../contentMedia/Custom-Connector-create-azure-function.png)
25+
26+
6. Once deployment is complete, go to your new Function App.
27+
7. Select **Create function**.
28+
8. If asked, select: **Development environment: Develop in portal**.
29+
9. Select **HTTP trigger** as the template, give it the name `GetAssets`, and set **Authorization level** to **Anonymous** (no authentication required).
30+
![Create HTTP trigger](../contentMedia/Custom-Connector-create-GetAssets.png)
31+
32+
10. Click **Create** to create the function.
33+
11. In the **Code + Test** tab, replace the function code with the mock API code from the next section.
34+
12. Click **Save**.
35+
36+
## 2. Implement the Mock API
37+
38+
Edit `GetAssets/index.js` to return a mock list of assets:
39+
40+
```js
41+
module.exports = async function (context, req) {
42+
context.res = {
43+
// status: 200, /* Defaults to 200 */
44+
body: [
45+
{ id: 1, name: "Laptop", type: "Electronics", status: "Available" },
46+
{ id: 2, name: "Projector", type: "Electronics", status: "In Use" },
47+
{ id: 3, name: "Desk", type: "Furniture", status: "Available" },
48+
{ id: 4, name: "Office Chair", type: "Furniture", status: "In Use" },
49+
{ id: 5, name: "Monitor", type: "Electronics", status: "Available" },
50+
{ id: 6, name: "Whiteboard", type: "Office Supply", status: "Available" },
51+
{ id: 7, name: "Phone", type: "Electronics", status: "In Use" },
52+
{ id: 8, name: "Tablet", type: "Electronics", status: "Available" },
53+
{ id: 9, name: "Printer", type: "Electronics", status: "Maintenance" },
54+
{ id: 10, name: "Filing Cabinet", type: "Furniture", status: "Available" }
55+
]
56+
};
57+
};
58+
```
59+
60+
## 3. Expose Your Function App via API Management
61+
62+
1. In the Azure Portal, search for and select **API Management services**.
63+
2. Click **+ Create** to create a new API Management instance (the Developer tier is free for development/testing).
64+
3. Fill in the required details and deploy the instance.
65+
4. Once deployed, open your API Management instance.
66+
5. In the left menu, select **APIs** > **+ Add API** > **Function App**.
67+
![Add API](../contentMedia/Custom-Connector-APIM-create-api.png)
68+
6. Select your Function App and the `GetAssets` function.
69+
![Import API](../contentMedia/Custom-Connector-APIM-import-api.png)
70+
7. Complete the wizard to import your function as an API operation.
71+
8. After import, go to your API in API Management.
72+
9. In the top menu, select **Settings** for your API.
73+
10. Under **Security**, set **Subscription required** to **Off**. This will remove the need for a subscription key (API key) when calling the API.
74+
![Update security settings](../contentMedia/Custom-Connector-APIM-security-subscription.png)
75+
11. Save your changes.
76+
77+
## 4. Create a Custom Connector in Power Platform Using API Management (from Azure Portal)
78+
79+
1. In **API Management Services** In the left menu within APIs, select **Power Platform**
80+
2. Select **Create a connector**.
81+
3. Select Your API
82+
![Create custom connector](../contentMedia/Custom-Connector-APIM-create-connector.png)
83+
4. Select your environment, display name and select **Create**. The custom connector will be created in your selected environment.
84+
5. In the [Power Apps maker portal](https://make.powerapps.com/), go to **Custom connectors** to review, edit, and test your new connector.
85+
![Test custom connector](../contentMedia/Custom-Connector-test-connector.png)
86+
87+
## 5. Next Steps
88+
- Expand the API with more operations as needed. Don't forget to update the connector with the new operations when you do.
89+
- Secure your API if you move beyond development/testing.
90+
91+
---
92+
This simple API provides a mock asset list and is ready for integration with Power Platform using a custom connector via API Management.

0 commit comments

Comments
 (0)