Table of Contents

RDW00001: Implicit body binding

Severity: Information  ·  Family: RDW (RDCore.Web)  ·  Raised by: ImplicitBodyBindingAnalyzer

The request body of an action binds to a parameter that no '@FromBody annotation names.

An action that takes a body ('@HttpPost, '@HttpPut, '@HttpPatch) binds the JSON body of the request to one of its parameters. '@FromBody("<parameter>"), written above the procedure with its HTTP method annotations, names that parameter. Without it, the body binds to the first parameter the route does not bind. The binding works either way. The annotation says which parameter receives the body, so that a reader of the procedure does not have to work it out from the route.

It is reported at the parameter the body binds to. A GET has no body and is never reported, nor is a DELETE, which binds a body only with '@FromBody.

How it is raised

Situation Example Resolution
A POST with no '@FromBody. '@HttpPost("{id}") above Public Function Place(ByVal id As Variant, ByVal order As Variant): the body binds to order. Add '@FromBody("order") above the procedure.
A POST whose route binds every parameter but one. '@HttpPost above Public Function Create(ByVal order As Variant): the body binds to order. Add '@FromBody("order") above the procedure.

Quick fix

The diagnostic comes with a quick fix, Name the body parameter, which writes '@FromBody("<parameter>") on a line of its own above the procedure, under its HTTP method annotations.

It is not offered when the action has several HTTP method annotations whose routes leave the body to different parameters: naming one of them would leave another route with its body in its route, which the host refuses to serve.

See also