Read request headers in Azure Functions v4 with Node

Thomas Pentenrieder
medialesson
Published in
6 days ago

I often have to read information from request headers in Azure Functions. For example to get the User Object ID that made an authenticated call. This is a bit more tricky than just calling:

const userId = request.headers['x-ms-client-principal-id'];

This is valid TypeScript but will always be undefined!

Turns out you first have to invoke the .entries() method on the request.headers, so here’s a quick helper method:

So now you can simply get a header value by calling

const userId = readHeader(request, 'x-ms-client-principal-id');

Originally published at https://medienstudio.net on August 12, 2024.

--

--