I have created Http Trigger Azure Function and its default return type is Task<IActionResult>.
Is there any difference if I changed it to Task<HttpResponseMessage>?
Azure function with Task<IActionResult> return type:
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
Azure function with Task<HttpResponseMessage>
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]
HttpRequestMessage message,
Is there any difference if I changed
Task<IActionResult>toTask<HttpResponseMessage>?
You can use the Task<HttpResponseMessage> to be the return type of your function. There shouldn't be a problem in executing with that.
Having said that, the difference between using the two lies in just the way you return response from your function.
IActionResult type of response, there is lesser code
to write while constructing a response and it makes unit testing
simpler. HttpResponseMessage gives more control on the
Http response message sent across the wire.Just as a side note,
In HttpTrigger Azure function v1.0, types Task<HttpResponseMessage> and HttpRequestMessage were used as defaults for return type and request type respectively.
From v2.0 onwards, types Task<IActionResult> and HttpRequest are being used as default return type and request type respectively as it conforms to .net core API structure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With