Just a quick post today, but this one unfortunately sidetracked me for a bit. Just remember a couple of things:

  • Always ensure that when providing objects as body of a POST request, that you use JSON.stringify to properly encode them.
  • A GET request using fetch cannot have body content associated with it. The body content in JSON is best used with POST or PATCH requests. My dilemma was that I had copied one fetch request, which was a POST request and started using it as a GET without removing the declaration of the body content.
  • When sending body content in a POST, ensure that the content-type is set to application/json. Otherwise, it will treat the body content as plaintext, which would explain why my req.body was coming back as undefined.

Just a couple of REST reminders as you go out and make your APIs and request routes.