-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathhttpPostBodyFunction.js
More file actions
31 lines (27 loc) · 898 Bytes
/
httpPostBodyFunction.js
File metadata and controls
31 lines (27 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const { app } = require('@azure/functions');
app.http('httppost', {
methods: ['POST'],
authLevel: 'function',
handler: async (request, context) => {
context.log(`Http function processed request for url "${request.url}"`);
try {
const person = await request.json();
const { name, age } = person;
if (!name || !age) {
return {
status: 400,
body: 'Please provide both name and age in the request body.'
};
}
return {
status: 200,
body: `Hello, ${name}! You are ${age} years old.`
};
} catch (error) {
return {
status: 400,
body: 'Invalid request body. Please provide a valid JSON object with name and age.'
};
}
}
});