title: Best way to parse out incoming HTTP post request on Arduino?
body: <p>I'm writing a simple HTTP webserver on my <a href="https://store.arduino.cc/usa/arduino-uno-wifi-rev2" rel="nofollow noreferrer">Arduino Uno Wifi Rev2</a> to handle an incoming HTTP POST Request in JSON format.</p>
  
  <p>This is how I'm sending the HTTP request (with JSON) from my client:</p>
  
  <pre><code>curl \
  --request POST \
  --header "Content-Type: application/json" \
  --data '{
      "A": "B",
      "C": "D"    
  }' \
  "http://192.168.4.1/myEndpoint"
  </code></pre>
  
  <p>This is the string the Arduino web-server receives:</p>
  
  <pre><code>POST /myEndpoint HTTP/1.1\r\nHost: 192.168.4.1\r\nUser-Agent: curl/7.54.0\r\nAccept: */*\r\nContent-Type: application/json\r\nContent-Length: 34\r\n\r\n{\n    "A": "B",\n    "C": "D"    \n}
  </code></pre>
  
  <p>I'm using <a href="https://github.com/nickgammon/Regexp" rel="nofollow noreferrer">Nick Gammon's Arduino Regexp library</a> to parse this request, validate it and extract the JSON data. </p>
  
  <p>This works, but parsing the HTTP request in this way is extremely brittle and feels hacky. It could easily break if a different client re-orders/omits a header or skips the carriage return characters. This is the god-awful regexp I'm using for validation:</p>
  
  <pre><code>    httpRegexp = "POST /myEndpoint HTTP/[%d%.]+%\r%\nHost: 192%.168%.4%.1%\r%\nUser%-Agent: curl/[%d%.]+%\r%\nAccept: %*/%*%\r%\nContent%-Type: application/json%\r%\nContent%-Length: %d+%\r%\n%\r%\n{%s*\"[A-Za-z]+\"%s*:%s*\".+\"%s*,%s*\"[A-Za-z]+\"%s*:%s*\".+\"%s*}";
  </code></pre>
  
  <p>Is there a better/recommended way for me to validate and parse the HTTP request? This must be a problem that others have already encountered and solved. Please post a code fragment solving this issue if possible.</p>