Direct an Azure Function App to accept only Application/json

599 views Asked by At

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...

1

There are 1 answers

0
Cindy Pau On

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: