Skip to main content

required-content-type-header-for-request-body

Overview

This rule belongs to the apimatic-gavel-validation ruleset and states that:

When the request level body is defined, a Content-Type header entry must also be present in the headers section to help us understand how the body information is structured so it can be processed further accordingly.

PropertyValue
EnabledYes
Maximum SeverityError
MessageRequest Content-Type header is missing from headers even though body is non-empty.
CodeAPIMATICGAVEL_V003
TypeValidation
Rule SystemSemantic
Broad CategoryGavel Request
Products ImpactedAPI Transformer, Code Generation, Developer Experience Portal
Tagsgavel apimatic semantic validation content type header request body body form request

Suggested Fixes

  • Ensure that a headers property exists in the request object.
  • Ensure that if body is set, an entry for the Content-Type header exists in the headers key value pairs.
  • Ensure that the Content-Type header name defined in the headers section has no typos.
  • If the body is expected to take in raw data, define a Content-Type header value accordingly e.g. text/plain for strings and numbers, application/json for JSON data, application/xml for XML data, etc.
  • If the body is expected to take a file/binary data as input, you may be looking for the multipart/form-data Content-Type header value.
  • If the body is expected to have key-value pairs structured like a query string, you may be looking for the application/x-www-form-urlencoded Content-Type header value.
  • Remove the body property definition from the request object if no request payload is expected.

For More Information