0

I'm trying to set the value of the Content-Length property to 0 in my RAML file.
I first stumbled upon this thread : How to specify API request header value in RAML

When I tried implementing it with this code :

/update:
  post:
    description: Store updated data in database
    headers:
      Content-Length:
        enum: [0]
    body:
      ...

I got the response 400 Bad Request :

   {
  "code": "REQUEST_VALIDATION_ERROR",
  "message": "Required header Content-Length is missing."
  }

My IDE told me a string was expected but feeding with ["0"] didn't solve the problem. (I'm testing my API specification in Mulesoft Design Center.)

So is there something I did wrong or is there another way to set the Content-Length to 0 in the request's header ?

Henry Mont
  • 337
  • 1
  • 3
  • 13
  • why are you trying to send a POST with zero length (ie no body)? – aled May 03 '22 at 10:28
  • The client does not need to provide data through the body because the data is being retrieved through some external API's call. But in the end I am inserting the retrieved data in the database. As the call is modifying my db, I don't want to use GET. – Henry Mont May 03 '22 at 12:14

1 Answers1

0

You should only try to define custom headers in RAML. A required header of the HTTP protocol like Content-Length must not be defined. It should be automatically generated to prevent errors.

aled
  • 21,330
  • 3
  • 27
  • 34
  • I read somewhere that the POST request with empty body could be denied by some proxies if a content-length of 0 is not specified. Is that untrue ? – Henry Mont May 03 '22 at 12:17
  • 1
    It is kind of required but it is complex. See this answer: https://stackoverflow.com/a/14759645/721855. Just let the tool generate it based on the body, and send the body empty. RAML doesn't have a good way to model empty bodies as far as I know. – aled May 03 '22 at 15:13