Monthly Archives: February 2020

Returning HTML from an Azure Function

After spending a lot of time with AWS Lambdas, I’m exploring Azure functions. The out of the box example just returns a OkObjectResult as a IActionResult.

Despite googling I couldn’t work out how to return HTML in the OkObjectResult with the correct content-type (“text/html”) but it turns out I needed instead to return a ContentResult:

    [FunctionName("HelloHTML")]
    public static async Task<IActionResult> HelloHTML([HttpTrigger(AuthorizationLevel.Function, "get", Route = "hello_html")]
                                                      HttpRequest req,
                                                      ILogger log) {
      return new ContentResult { Content = "<html><body>Hello <b>world</b></body></html>", ContentType = "text/html" };
    }