Skip to content
This repository was archived by the owner on Jun 3, 2023. It is now read-only.

HttpBodyAttribute

Jussi Saarivirta edited this page Jan 26, 2019 · 1 revision

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");
}

Clone this wiki locally