Creating an API that integrates with React (frontend) and Azure (cloud hosting/backend services) involves several components:
- Backend API – e.g., using Node.js, .NET Core, Python, etc.
- Hosting the backend on Azure – e.g., Azure App Service or Azure Functions
- Connecting React frontend to the API
- Authentication & Security (optional but recommended) – e.g., Azure AD, CORS
✅ Step-by-Step Guide to Build a Simple API for React + Azure Integration
We'll use:
- Node.js Express API as the backend
- Azure App Service to host the API
- React app calling the API
🧱 1. Create the Backend API (Node.js + Express)
1.1 Initialize Project
mkdir my-api
cd my-api
npm init -y
npm install express cors dotenv
1.2 server.js
const express = require('express');
const cors = require('cors');
require('dotenv').config();
const app = express();
const PORT = process.env.PORT || 5000;
app.use(cors());
app.use(express.json());
app.get('/api/hello', (req, res) => {
res.json({ message: 'Hello from Azure!' });
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
1.3 .env
PORT=5000
1.4 Add start script in package.json
"scripts": {
"start": "node server.js"
}
You can test this locally by running:
npm start
Then visit: http://localhost:5000/api/hello
☁️ 2. Deploy the API to Azure App Service
2.1 Prerequisites
- Azure Account (free trial available)
- Azure CLI
- Git installed
2.2 Login to Azure CLI
az login
2.3 Create Resource Group
az group create --name myResourceGroup --location eastus
2.4 Create App Service Plan
az appservice plan create --name myAppServicePlan --resource-group myResourceGroup --sku FREE --is-linux
2.5 Create Web App
az webapp create --resource-group myResourceGroup --plan myAppServicePlan --name <your-app-name> --runtime "NODE|18-lts" --deployment-local-git
Note: Replace <your-app-name> with a unique name like my-react-api-123.
2.6 Get Deployment Credentials
az webapp deployment list-publishing-credentials --name <your-app-name> --resource-group myResourceGroup
Use these credentials to push via Git.
2.7 Push Code to Azure
git remote add azure <git-deployment-url-from-above>
git add .
git commit -m "Initial commit"
git push azure master
After deployment, your API will be live at:
https://<your-app-name>.azurewebsites.net
Try visiting:
https://<your-app-name>.azurewebsites.net/api/hello
💻 3. Connect Your React App to the API
In your React app (my-react-app), make API calls like this:
Example: App.js
import React, { useEffect, useState } from 'react';
function App() {
const [message, setMessage] = useState('');
useEffect(() => {
fetch('https://<your-app-name>.azurewebsites.net/api/hello')
.then(res => res.json())
.then(data => setMessage(data.message));
}, []);
return (
<div>
<h1>Azure API Response:</h1>
<p>{message}</p>
</div>
);
}
export default App;
Make sure you enable CORS in your Express app if needed.
🔐 Optional: Secure with Authentication
You can secure your API using:
- Azure Active Directory (AAD) authentication
- API Keys
- JWT tokens
Let me know if you want to implement auth!
✅ Summary
| Component | Tool |
|---|
| Backend API | Express (Node.js) |
| Hosting | Azure App Service |
| Frontend | React |
| Communication | HTTP/Fetch/Axios |
| Optional Auth | Azure AD / JWT |
🚀 Bonus Tips
- Use Azure DevOps or GitHub Actions for CI/CD pipelines
- Monitor with Application Insights
- Store secrets in Azure Key Vault
Would you like me to generate a full starter template (with GitHub repo structure or ZIP download)? Or integrate with Azure Functions instead of App Service?