Learn AZURE-FUNCTIONS with Real Code Examples
Updated Nov 25, 2025
Code Sample Descriptions
1
Simple Azure Function (JavaScript)
# azure/demo/index.js
module.exports = async function (context, req) {
context.res = {
status: 200,
body: 'Hello, Azure!'
};
};
A simple Azure Function responding with 'Hello, Azure!' to HTTP requests.
2
Azure Function with Query Parameters
# azure/demo/query.js
module.exports = async function (context, req) {
const name = req.query.name || 'Guest';
context.res = {
status: 200,
body: `Hello, ${name}!`
};
};
Reads query parameters and responds with a personalized message.
3
Azure Function with JSON Response
# azure/demo/json.js
module.exports = async function (context, req) {
context.res = {
status: 200,
body: { message: 'Hello, JSON!' }
};
};
Returns a JSON object in the response body.
4
Azure Function POST Handler
# azure/demo/post.js
module.exports = async function (context, req) {
const data = req.body;
context.res = {
status: 200,
body: `Received: ${data.input}`
};
};
Handles POST requests and parses JSON body.
5
Azure Function with Environment Variables
# azure/demo/env.js
module.exports = async function (context, req) {
const secret = process.env.MY_SECRET || 'No Secret';
context.res = {
status: 200,
body: `Secret is: ${secret}`
};
};
Uses environment variables in the function.
6
Azure Function Redirect
# azure/demo/redirect.js
module.exports = async function (context, req) {
context.res = {
status: 302,
headers: { 'Location': 'https://azure.microsoft.com/' },
body: ''
};
};
Responds with a redirect to another URL.
7
Azure Function Error Handling
# azure/demo/error.js
module.exports = async function (context, req) {
try {
throw new Error('Something went wrong');
} catch(err) {
context.res = {
status: 500,
body: err.message
};
}
};
Demonstrates returning an error response.
8
Azure Function Delayed Response
# azure/demo/delay.js
module.exports = async function (context, req) {
await new Promise(resolve => setTimeout(resolve, 1000));
context.res = {
status: 200,
body: 'Delayed Hello!'
};
};
Returns a response after a simulated delay.
9
Azure Function Fetch External API
# azure/demo/fetch.js
const fetch = require('node-fetch');
module.exports = async function (context, req) {
const response = await fetch('https://api.github.com');
const data = await response.json();
context.res = {
status: 200,
body: data
};
};
Fetches data from an external API and returns it.
10
Azure Function with Custom Headers
# azure/demo/headers.js
module.exports = async function (context, req) {
context.res = {
status: 200,
headers: { 'X-Custom-Header': 'AzureFunction' },
body: 'Hello with headers'
};
};
Returns custom HTTP headers in the response.