0

I have created following Azure isolated function. Instead of returning simple json object it returns the below json object.

[Function("GetSync")]
public async Task<IActionResult> GetSync(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getsync/{Id:guid}")] HttpRequestData req, Guid Id)
{
     var responseObject = new { Message = "Hello, world!", TimeStamp = DateTime.Now };

     return new OkObjectResult(responseObject);
}

Response is

{
  "Value": {
    "Message": "Hello, world!",
    "TimeStamp": "2023-05-31T21:16:38.0833691+10:00"
  },
  "Formatters": [],
  "ContentTypes": [],
  "DeclaredType": null,
  "StatusCode": 200
}

Also I have notice the content type of the response header is "text/plain; charset=utf-8"

But if I create a in-process function as below, it returns the json object correctly

[FunctionName("GetSync")]
public static async Task<IActionResult> GetSync(
       [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getsync/{Id:guid}")] HttpRequest req, Guid Id)
{
       var responseObject = new { Message = "Hello, world!", TimeStamp = DateTime.Now };

        return new OkObjectResult(responseObject);
}

Response for above request is

{
    "message": "Hello, world!",
    "timeStamp": "2023-05-31T20:09:41.0307775+10:00"
}

Any idea how can I fix the isolate Azure function to return a proper json object?

Ash
  • 447
  • 2
  • 6
  • 19
  • Check the docs for changes in isolated model: https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide#http-trigger. Basically you should return an HttpResponseData object from the function. – juunas May 31 '23 at 12:59

0 Answers0