HttpBodyAttribute - Jusas/AzureFunctionsV2.HttpExtensions GitHub Wiki

HttpBodyAttribute

Annotation for a HttpParam indicating that its value comes from the HttpRequest body.

Contains Required property (if true, throws exception when body is empty).

Default deserialization handles application/json, application/xml and text/plain content types.

Example:

POST http://localhost:7071/api/post-object
Content-Type: application/json

{
  "name": "John",
  "boolean": true,
  "numbers": [1,2,3]
}

### Or as XML

POST http://localhost:7071/api/post-object
Content-Type: application/xml

<MyObject>
    <Boolean>true</Boolean>
    <Name>John</Name>
    <Numbers>
      <int>1</int>
      <int>2</int>
      <int>3</int>
    </Numbers>
</MyObject>
[FunctionName("BodyParametersDemo1")]
public static async Task<IActionResult> PostObject(
    [HttpTrigger(AuthorizationLevel.Function, "post", Route = "post-object")] HttpRequest req,
    [HttpBody]HttpParam<MyObject> bodyData,            
    ILogger log)
{
    log.LogInformation($"Object received: {JsonConvert.SerializeObject(bodyData.Value)}");
    return new OkObjectResult("ok");
}
⚠️ **GitHub.com Fallback** ⚠️