Isolated Azure Function returns whole context in the body

464 Views Asked by At

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?

0

There are 0 best solutions below