1

Direct an Azure Function App to accept only Application/json

Hi, I'm using an Azure Function and testing it through Postman.

My requirement is when we pass Content-Type other than "application/json", I'm expecting my Azure Function to return saying "Invalid Content - Type".

The above need I'm able to achieve with the Code changes as below.

if(HTTPRequest.Headers["Content-Type"] != "application/json") -- then returing "Invalid Content - Type"

But is it possible and is there any way we can achieve the same using Configuration Setting (i.e host.json) in Azure Function App ?

Also, I have tried adding the below under customHeaders in host.json file. But it didn't work.

"Accept": "application/json"

"Access-Control-Expose-Headers": "application/json"

Thanks in Advance...

Sathya
  • 55
  • 5
  • For V1 function, we set webHookType as genericJson in function.json,see: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-trigger?tabs=csharp#configuration – Stanley Gong Mar 17 '21 at 10:35
  • Hi Stanley, Thanks for your reply. As per the documentation, webHookType is applicable to V1 function. (i.e Supported only for the version 1.x runtime). In our case, we are using Version 2.x So I'm still exploring available options to achieve this need. – Sathya Mar 17 '21 at 11:10

1 Answers1

0

But is it possible and is there any way we can achieve the same using Configuration Setting (i.e host.json) in Azure Function App ?

No, azure function v2 host.json doesn't have this setting.

And Webhooktype attribute has been removed. Now it is not supported in azure function v2:

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27