func init + func new
For deploying to Azure
Create an Azure Function with HTTP trigger using the v4 programming model.
1 import { app, HttpRequest, HttpResponseInit, InvocationContext } from '@azure/functions'; 2 3 app.http('processOrder', { 4 methods: ['POST'], 5 authLevel: 'function', 6 handler: async (req: HttpRequest, ctx: InvocationContext): Promise<HttpResponseInit> => { 7 const body = await req.json() as { orderId: string; amount: number }; 8 9 if (!body.orderId || body.amount <= 0) { 10 return { status: 400, jsonBody: { error: 'Invalid request' } }; 11 } 12 13 ctx.log(`Processing order: ${body.orderId}`); 14 // Business logic here 15 return { 16 status: 200, 17 jsonBody: { transactionId: `txn-${Date.now()}`, orderId: body.orderId } 18 }; 19 }, 20 });
curl POST localhost:7071/api/processOrder returns JSON response
Sign in to share your feedback and join the discussion.