Closed
Description
When using http streams, the request.params
object will be an empty object. The suggested workaround is to use a package like path-to-regexp to parse the request.url
property. Keep in mind that Azure Functions only supports ASP.NET Core route templates (i.e. user/{name}
) when registering your function, so you will likely need to use a different syntax (i.e. /user/:name
) when parsing the url. Here is example code using the suggested workaround:
import { app, HttpRequest, HttpResponseInit, InvocationContext } from '@azure/functions';
import { match } from 'path-to-regexp';
export async function httpTrigger1(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
const parseRoute = match('/api/user/:name');
const route = parseRoute(new URL(request.url).pathname);
const params = route ? (route.params as Record<string, string>) : {};
const name = params.name || 'world';
return { body: `Hello, ${name}!` };
}
app.http('httpTrigger1', {
methods: ['GET', 'POST'],
route: 'user/{name}',
authLevel: 'anonymous',
handler: httpTrigger1,
});
Related to Azure/azure-functions-host#9840